Skip to content

Instantly share code, notes, and snippets.

@Manoj-nathwani
Created January 30, 2019 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Manoj-nathwani/3638317585a550414078caba67798492 to your computer and use it in GitHub Desktop.
Save Manoj-nathwani/3638317585a550414078caba67798492 to your computer and use it in GitHub Desktop.
id,lat,lon ---> id,city,country
# -*- 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