Skip to content

Commit f6ef17e

Browse files
committed
Fixed API
- Remove population attribute from OSM if value is NULL - Default method of `geocoder.ip` is now ipinfo instead of Maxmind - When <blank> is entered in Maxmind, it will search your own IP address.
1 parent 02e3044 commit f6ef17e

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

geocoder/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def ip(location, **kwargs):
372372
:param location: (optional) if left blank will return your
373373
current IP address's location.
374374
"""
375-
return get(location, provider='maxmind', **kwargs)
375+
return get(location, provider='ipinfo', **kwargs)
376376

377377

378378
def canadapost(location, **kwargs):

geocoder/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ def osm(self):
284284
if self.postal:
285285
osm['addr:postal'] = self.postal
286286
if hasattr(self, 'population'):
287-
osm['population'] = self.population
287+
if self.population:
288+
osm['population'] = self.population
288289
return osm
289290

290291
@property

geocoder/canadapost.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,5 @@ def unit(self):
157157
return self.parse.get('SubBuilding')
158158

159159
if __name__ == '__main__':
160-
g = Canadapost("4 2023 4th Ave W, Vancouver")
160+
g = Canadapost("453 Booth Street, ON")
161161
g.debug()

geocoder/maxmind.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ class Maxmind(Base):
2121
provider = 'maxmind'
2222
method = 'geocode'
2323

24-
def __init__(self, location='me', **kwargs):
25-
self.location = location
24+
def __init__(self, location, **kwargs):
25+
if location:
26+
self.location = location
27+
else:
28+
self.location = 'me'
2629
self.headers = {
2730
'Referer': 'https://www.maxmind.com/en/geoip_demo',
2831
'Host': 'www.maxmind.com',
@@ -110,5 +113,5 @@ def metro_code(self):
110113
return self.parse['location'].get('metro_code')
111114

112115
if __name__ == '__main__':
113-
g = Maxmind('me')
116+
g = Maxmind('8.8.8.8')
114117
g.debug()

geocoder/osm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,5 +323,5 @@ def place_rank(self):
323323

324324

325325
if __name__ == '__main__':
326-
g = Osm('1552 Payette dr, Ottawa ON')
327-
g.debug()
326+
g = Osm('New York City')
327+
print(g.osm)

0 commit comments

Comments
 (0)