Closed Suleman-Elahi closed 4 years ago
There appear to be two separate issues:
secrets.ini.example
is incorrect, andFor the first issue, remove the quotes around the string. What was happening for me is that an extra tick was getting added to the string. That is, if my key was abc123
, then python was calling the API with my key as abc123'
. Using the following, unquoted template fixed the issue:
# Rename this file to 'secrets.ini'.
[API_KEYS]
GOOGLE_MAPS = API_Key
For the second, use the -X utf8=1
argument:
python -X utf8=1 fetch.py --directory output/england/london --rating 4.5 --reviews 5000 --operator and --query "attractions in London"
@xobs - I have updated the secrets.ini.example
and removed the quotations. For the second issue, I'm not sure where the non-ASCII characters come from. Perhaps it's the text from the Wikipedia article. Can you confirm if the issue still persists if you remove the print
statement?
@Suleman-Elahi you might want to double-check you are using Python 3.6 or above.
I'm using Python 3.7.3. Here is the output when I try to search for something in Tiblisi, Georgia:
❯ python fetch.py --directory output/georgia/tiblisi --rating 4.5 --reviews 5000 --operator and --query "attractions in tiblisi"
Attractions In Tiblisi -> ['National Botanical Garden of Tbilisi city', (41.685574, 44.8029141), 'tourist_attraction, park, point_of_interest, establishment', 4.6, '12 Bambis Rigi Street, Tbilisi, Georgia', "Tbilisi (English: tə-bih-LEE-see, tə-BIL-ih-see; Georgian: თბილისი [tʰbilisi] (listen)), in some countries also still known by its pre-1936 international designation Tiflis ( TIF-lis), is the capital and the largest city of Georgia, lying on the banks of the Kura River with a population of approximately 1.5 million people. Founded in the 5th century AD by Vakhtang I of Iberia, since then Tbilisi served as the capital of various Georgian kingdoms and republics. Between 1801 and 1917, then part of the Russian Empire, Tbilisi was the seat of the Imperial Viceroy, governing both Southern and Northern Caucasus.Because of its location on the crossroads between Europe and Asia, and its proximity to the lucrative Silk Road, throughout history Tbilisi was a point of contention among various global powers. The city's location to this day ensures its position as an important transit route for various energy and trade projects. Tbilisi's diverse history is reflected in its architecture, which is a mix of medieval, neoclassical, Beaux Arts, Art Nouveau, Stalinist and the Modern structures.Historically, Tbilisi has been home to people of multiple cultural, ethnic, and religious backgrounds, though it is currently overwhelmingly Eastern Orthodox Christian. Its notable tourist destinations include cathedrals Sameba and Sioni, Freedom Square, Rustaveli Avenue and Agmashenebeli Avenue, medieval Narikala Fortress, the pseudo-Moorish Opera Theater, and the Georgian National Museum.The climate in Tbilisi mostly ranges between 30°C to 18°C.", 'https://en.wikipedia.org/wiki/Tbilisi', 6786]
Traceback (most recent call last):
File "fetch.py", line 112, in <module>
writer.writerow(data)
File "D:\Software\Miniconda3\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u0259' in position 189: character maps to <undefined>
smcro@CUBOID yosys-bld D:\Code\trip-planner master ≢ [09:08]
❯ python --version
Python 3.7.3
smcro@CUBOID yosys-bld D:\Code\trip-planner master ≢ [09:09]
❯
The following diff fixes the issue:
diff --git a/fetch.py b/fetch.py
index 778a8af..07cc9f0 100644
--- a/fetch.py
+++ b/fetch.py
@@ -60,7 +60,7 @@ filename = ' '.join([q.capitalize() for q in query])
wikipedia.set_lang(args.language)
columns = ['name', 'coordinates', 'types', 'rating', 'formatted address', 'summary', 'url', 'reviews']
-with open(args.directory + f'/{filename}.csv', 'w') as out_file:
+with open(args.directory + f'/{filename}.csv', 'w', encoding='utf-8') as out_file:
writer = csv.writer(out_file, delimiter='|')
writer.writerow(columns)
for place in places:
@Suleman-Elahi you might want to double-check you are using Python 3.6 or above.
Yeah, my Python version is 3.7.1. I had the same issue on Linux though.
@Suleman-Elahi I assume you mean you had the same No results found for query
error, in which case it's probably caused by quoting your API key inside settings.yaml
. Remove the quote and see if that fixes it.
Yeah, thanks man. It is working on Windows now.
And Linux:
encoding='utf-8'
@xobs Thanks for proposing the fix. Pushed into master in: https://github.com/adl1995/trip-planner/commit/22ba61ca4cab5bbd561e620819cb0be1b9d966e8