Created
January 30, 2019 15:15
-
-
Save Manoj-nathwani/3638317585a550414078caba67798492 to your computer and use it in GitHub Desktop.
id,lat,lon ---> id,city,country
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import csv, os, time | |
from geopy.geocoders import Nominatim | |
THIS_FOLDER = os.path.dirname(os.path.abspath(__file__)) | |
my_file = os.path.join(THIS_FOLDER, 'data.csv') | |
geolocator = Nominatim() | |
with open(my_file, 'r') as csvFile: | |
reader = csv.reader(csvFile) | |
enabled = True | |
for row in reader: | |
if not enabled: | |
if int(row[0]) == 6615: | |
enabled = True | |
continue | |
time.sleep(1) | |
location = geolocator.reverse((row[1], row[2])) | |
try: | |
if 'city' in location.raw['address']: | |
town_or_city = location.raw['address']['city'] | |
elif 'town' in location.raw['address']: | |
town_or_city = location.raw['address']['town'] | |
print(','.join([ | |
row[0], | |
town_or_city, | |
location.raw['address']['country'] | |
])) | |
except: | |
print(location.raw['address'].keys()) | |
import pdb; pdb.set_trace() | |
pass | |
csvFile.close() | |
#print(location.address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment