summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2020-09-28 22:52:48 +0300
committerYuval Adam <_@yuv.al>2020-09-28 22:52:48 +0300
commit7d5644d3e7b1362820a7820bdf98e1209a30de68 (patch)
treebeee18acd3f438c6e30fe49f580d219f9b9fd17d
parent927a83fd865aedce21a27bfe7016cba0a2815016 (diff)
Fix GeoIP path configs
-rw-r--r--iss/config.py9
-rw-r--r--iss/geo.py4
-rw-r--r--iss/tests/test_geo.py5
3 files changed, 13 insertions, 5 deletions
diff --git a/iss/config.py b/iss/config.py
index 1248bb3..6850ea3 100644
--- a/iss/config.py
+++ b/iss/config.py
@@ -1,3 +1,10 @@
from os import environ
-GEOIP_CITY_PATH = environ.get("GEOIP_GEOLITE2_CITY_FILENAME")
+GEOIP_GEOLITE2_PATH = environ.get("GEOIP_GEOLITE2_PATH")
+GEOIP_GEOLITE2_CITY_FILENAME = environ.get(
+ "GEOIP_GEOLITE2_CITY_FILENAME", "GeoLite2-City.mmdb"
+)
+
+GEOIP_GEOLITE2_CITY_PATH = None
+if GEOIP_GEOLITE2_PATH:
+ GEOIP_GEOLITE2_CITY_PATH = GEOIP_GEOLITE2_PATH + GEOIP_GEOLITE2_CITY_FILENAME
diff --git a/iss/geo.py b/iss/geo.py
index 55c8f02..5413913 100644
--- a/iss/geo.py
+++ b/iss/geo.py
@@ -2,7 +2,7 @@ from collections import namedtuple
import geoip2.database
import geoip2.errors
-from .config import GEOIP_CITY_PATH
+from .config import GEOIP_GEOLITE2_CITY_PATH
DEFAULT_LOCATION = {
"latitude": 34.7641,
@@ -16,7 +16,7 @@ default_location = namedtuple("Location", DEFAULT_LOCATION.keys())(
def get_location(ip):
- with geoip2.database.Reader(GEOIP_CITY_PATH) as reader:
+ with geoip2.database.Reader(GEOIP_GEOLITE2_CITY_PATH) as reader:
try:
res = reader.city(ip)
return res.location
diff --git a/iss/tests/test_geo.py b/iss/tests/test_geo.py
index c63c2d6..6c25b07 100644
--- a/iss/tests/test_geo.py
+++ b/iss/tests/test_geo.py
@@ -1,10 +1,11 @@
import pytest
-from ..config import GEOIP_CITY_PATH
+from ..config import GEOIP_GEOLITE2_CITY_PATH
from ..geo import get_location
geoip_required = pytest.mark.skipif(
- not GEOIP_CITY_PATH, reason="Path to GeoLite2 city database must be provided"
+ not GEOIP_GEOLITE2_CITY_PATH,
+ reason="Path to GeoLite2 city database must be provided",
)