The question is published on by Tutorial Guruji team.
So I have a large list of geographical locations that may be cities, counties, etc, in a particular country. For example country: Turkey and list of names is: Erzurum, Eskisehir, etc.
I am wondering if I can put this list into a text file and use Python to check these names online to check what geographical entity they are instead of just Googling each term individually. How would I do that?
You can also use google geocoding api. Here is an example:
erzurum istanbul turkey chicago united states india kayseri spain
Here is the code:
import urllib2 import json import time def getEntity( entityText ): url = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s' % urllib2.quote(entityText) response = urllib2.urlopen(url) jsonaddress = json.loads(response.read()) time.sleep(0.2) if jsonaddress['status'] == 'OK': return jsonaddress['results']['types'] else: return None with open('a.txt') as f: for line in f: entityText = line.strip() entity = getEntity( entityText ) print entityText, entity
erzurum locality istanbul locality turkey country chicago locality united states country india country kayseri locality spain country