Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Refer #11 and #18. Change Google method to place, requires language
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Hebing committed May 24, 2019
1 parent b3841ca commit 7af4f15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def extract_entities(title, text, language):
return r.json()


def add_geocodes(entities):
g = Geocoder(entities['text']['entities'], 'alexhebing')
def add_geocodes(args, entities):
g = Geocoder(entities['text']['entities'], args.language)

try:
g.geocode_locations()
Expand All @@ -105,7 +105,7 @@ def collect_data(args):
entities = extract_entities('test', text, args.language)

print("adding geocodes to locations from '{}'".format(filename))
add_geocodes(entities)
add_geocodes(args, entities)

export(args, filename, text, entities)
print("results for '{}' exported".format(filename))
Expand Down
7 changes: 4 additions & 3 deletions geocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class Geocoder:
is not present as an environment variable. Propagates geocoder's/requests' requests.exceptions.ConnectionError.
'''

def __init__(self, named_entities, geonames_username):
def __init__(self, named_entities, language):
if not "GEONAMES_USERNAME" in os.environ:
raise EnvironmentError("GEONAMES_USERNAME is not present as an environment variable. Please export it")
if not "GOOGLE_API_KEY" in os.environ:
raise EnvironmentError("GOOGLE_API_KEY is not present as an environment variable. Please export it")

self.named_entities = named_entities
self.language = language
self.geonames_username = os.getenv('GEONAMES_USERNAME')

def geocode_locations(self):
Expand Down Expand Up @@ -63,8 +64,8 @@ def set_geocode_from_osm(self, session, named_entity):

def set_geocode_from_google(self, session, named_entity):
place_name = named_entity['ne']
g = geocoder.google(place_name, session=session)

g = geocoder.google(place_name, session=session, method='places', language=self.language)
if (g.ok):
named_entity['google_lat'] = g.lat
named_entity['google_lng'] = g.lng
Expand Down

0 comments on commit 7af4f15

Please sign in to comment.