Skip to content

Commit 7147f7f

Browse files
committed
pls work
1 parent 980113c commit 7147f7f

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

plugins/geoip.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def fetch_db():
23-
r = requests.get(DB_URL, stream=True)
23+
r = requests.get(DB_URL)
2424
if r.status_code == 200:
2525
with gzip.open(r.raw, 'rb') as infile:
2626
with open(PATH, 'wb') as outfile:
@@ -31,23 +31,28 @@ def update_db():
3131
"""
3232
Updates the DB.
3333
"""
34-
if os.path.isfile(PATH):
35-
# check if file is over 2 weeks old
36-
if time.time() - os.path.getmtime(PATH) > (14 * 24 * 60 * 60):
37-
# geoip is outdated, re-download
38-
fetch_db()
39-
return geoip2.database.Reader(PATH)
40-
else:
41-
try:
42-
return geoip2.database.Reader(PATH)
43-
except:
44-
# issue loading, geo
34+
try:
35+
if os.path.isfile(PATH):
36+
# check if file is over 2 weeks old
37+
if time.time() - os.path.getmtime(PATH) > (14 * 24 * 60 * 60):
38+
# geoip is outdated, re-download
4539
fetch_db()
4640
return geoip2.database.Reader(PATH)
47-
else:
48-
# no geoip file
49-
fetch_db()
50-
return geoip2.database.Reader(PATH)
41+
else:
42+
try:
43+
return geoip2.database.Reader(PATH)
44+
except:
45+
# issue loading, geo
46+
fetch_db()
47+
return geoip2.database.Reader(PATH)
48+
else:
49+
# no geoip file
50+
print("calling fetch_db")
51+
fetch_db()
52+
print("fetch_db finished")
53+
return geoip2.database.Reader(PATH)
54+
except Exception as e:
55+
print(e)
5156

5257

5358
def check_db(loop):
@@ -60,8 +65,7 @@ def check_db(loop):
6065
logger.info("Loading GeoIP database")
6166
db = yield from loop.run_in_executor(None, update_db, geoip_reader)
6267
logger.info("Loaded GeoIP database")
63-
if db:
64-
geoip_reader = db
68+
geoip_reader = db
6569

6670

6771
@asyncio.coroutine

0 commit comments

Comments
 (0)