Skip to content

Commit 2938009

Browse files
committed
Okay, this works. Unless the plugin reloads while fetch is executing. @dabo can we get a run_once arg for onload hooks?
1 parent 7147f7f commit 2938009

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

plugins/geoip.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121

2222
def fetch_db():
23-
r = requests.get(DB_URL)
23+
logger.info("fetch called")
24+
if os.path.exists(PATH):
25+
os.remove(PATH)
26+
r = requests.get(DB_URL, stream=True)
2427
if r.status_code == 200:
2528
with gzip.open(r.raw, 'rb') as infile:
2629
with open(PATH, 'wb') as outfile:
@@ -52,7 +55,7 @@ def update_db():
5255
print("fetch_db finished")
5356
return geoip2.database.Reader(PATH)
5457
except Exception as e:
55-
print(e)
58+
print("GEOERROR" + e)
5659

5760

5861
def check_db(loop):
@@ -63,7 +66,7 @@ def check_db(loop):
6366
global geoip_reader
6467
if not geoip_reader:
6568
logger.info("Loading GeoIP database")
66-
db = yield from loop.run_in_executor(None, update_db, geoip_reader)
69+
db = yield from loop.run_in_executor(None, update_db)
6770
logger.info("Loaded GeoIP database")
6871
geoip_reader = db
6972

0 commit comments

Comments
 (0)