Commit e42b2aa7cec3c8a144a2dca8f284e5ad6ac86380
1 parent
b8ad872b
Exists in
master
Use path relativity in the geocoder.
Don't try to be clever with the interval between OSM queries.
Showing
1 changed file
with
5 additions
and
2 deletions
Show diff stats
flaskr/geocoder.py
... | ... | @@ -2,17 +2,20 @@ import geopy |
2 | 2 | import shelve |
3 | 3 | import time |
4 | 4 | |
5 | +from core import get_path | |
6 | + | |
5 | 7 | |
6 | 8 | class CachedGeocoder: |
7 | 9 | |
8 | 10 | def __init__(self, source="Nominatim", geocache="geocache.db"): |
9 | 11 | self.geocoder = getattr(geopy.geocoders, source)() |
10 | - self.cache = shelve.open(geocache, writeback=True) | |
12 | + self.cache = shelve.open(get_path(geocache), writeback=True) | |
11 | 13 | self.timestamp = time.time() + 1.5 |
12 | 14 | |
13 | 15 | def geocode(self, address): |
14 | 16 | if address not in self.cache: |
15 | - time.sleep(max(0, 1 - (time.time() - self.timestamp))) | |
17 | + # time.sleep(max(0, 1 - (time.time() - self.timestamp))) | |
18 | + time.sleep(1.618) | |
16 | 19 | self.timestamp = time.time() |
17 | 20 | self.cache[address] = self.geocoder.geocode( |
18 | 21 | query=address, | ... | ... |