-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathretrieve.py
61 lines (54 loc) · 1.58 KB
/
retrieve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
from util import MaxMindDB
def get_license_key(license_key='MAXMIND_LICENSE_KEY'):
"""
@param license_key: Name of environment variable
@return: license of MaxMindDB from environent variables as string
@return: in case of error, returns Exception, more specifically KeyError
"""
try:
maxmind_db_license = os.environ[license_key]
return maxmind_db_license
except Exception:
print("\nWARNING: No MAXMIND LICENSE KEY Found in environment variables")
print("Proceeding anyway...")
return 'NOLICENSEKEYFOUND'
def get_country_data():
"""
Download GeoLite2-Country data from MaxMind
"""
_ = MaxMindDB((
"https://download.maxmind.com/app/geoip_download?"
"edition_id=GeoLite2-Country&"
"license_key={license_key}&"
"suffix=tar.gz"
).format(
license_key=get_license_key(),
), "cc"
)
def get_asn_data():
"""
Download ASN data from MaxMind
"""
_ = MaxMindDB((
"https://download.maxmind.com/app/geoip_download?"
"edition_id=GeoLite2-ASN&"
"license_key={license_key}&"
"suffix=tar.gz"
).format(
license_key=get_license_key(),
), "asn"
)
def get_city_data():
"""
Download GeoLiteCity data from Maxmind DB
"""
_ = MaxMindDB((
"https://download.maxmind.com/app/geoip_download?"
"edition_id=GeoLite2-City&"
"license_key={license_key}&"
"suffix=tar.gz"
).format(
license_key=get_license_key(),
), "city"
)