diff --git a/app/location/__init__.py b/app/location/__init__.py index 1da5e9e5..3344da63 100644 --- a/app/location/__init__.py +++ b/app/location/__init__.py @@ -1,6 +1,6 @@ """app.location""" from ..coordinates import Coordinates -from ..utils import countries +from ..utils.countries import Country from ..utils.populations import country_population @@ -15,7 +15,7 @@ def __init__( ): # pylint: disable=too-many-arguments # General info. self.id = id - self.country = country.strip() + self.country = Country(country.strip()) self.province = province.strip() self.coordinates = coordinates @@ -35,7 +35,7 @@ def country_code(self): :returns: The country code. :rtype: str """ - return (countries.country_code(self.country) or countries.DEFAULT_COUNTRY_CODE).upper() + return (self.country.country_code(self.country) or Country.DEFAULT_COUNTRY_CODE).upper() @property def country_population(self): diff --git a/app/services/location/jhu.py b/app/services/location/jhu.py index ebed3960..920ce962 100644 --- a/app/services/location/jhu.py +++ b/app/services/location/jhu.py @@ -12,7 +12,7 @@ from ...coordinates import Coordinates from ...location import TimelinedLocation from ...models import Timeline -from ...utils import countries +from ...utils.countries import Country from ...utils import date as date_util from ...utils import httputils from . import LocationService @@ -98,7 +98,7 @@ async def get_category(category): { # General info. "country": country, - "country_code": countries.country_code(country), + "country_code": Country(country).country_code(), "province": item["Province/State"], # Coordinates. "coordinates": {"lat": item["Lat"], "long": item["Long"],}, diff --git a/app/utils/countries.py b/app/utils/countries.py index 9fb4f98a..f171609b 100644 --- a/app/utils/countries.py +++ b/app/utils/countries.py @@ -366,15 +366,20 @@ # "MS Zaandam" } -# fmt: on -def country_code(value): - """ - Return two letter country code (Alpha-2) according to https://en.wikipedia.org/wiki/ISO_3166-1 - Defaults to "XX". - """ - code = COUNTRY_NAME__COUNTRY_CODE.get(value, DEFAULT_COUNTRY_CODE) - if code == DEFAULT_COUNTRY_CODE: - # log at sub DEBUG level - LOGGER.log(5, f"No country code found for '{value}'. Using '{code}'!") +class Country: - return code + def __init__(self, name): + self.name = name + + # fmt: on + def country_code(value): + """ + Return two letter country code (Alpha-2) according to https://en.wikipedia.org/wiki/ISO_3166-1 + Defaults to "XX". + """ + code = COUNTRY_NAME__COUNTRY_CODE.get(value, DEFAULT_COUNTRY_CODE) + if code == DEFAULT_COUNTRY_CODE: + # log at sub DEBUG level + LOGGER.log(5, f"No country code found for '{value}'. Using '{code}'!") + + return code