Skip to content

Commit 390ceea

Browse files
authored
Merge pull request #214 from Bost/renaming
Renamings
2 parents 54174f6 + a0f5c00 commit 390ceea

File tree

5 files changed

+20
-21
lines changed

5 files changed

+20
-21
lines changed

app/location/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ..coordinates import Coordinates
2-
from ..utils import countrycodes
2+
from ..utils import countries
33
from ..utils.populations import country_population
44

55

@@ -31,7 +31,7 @@ def country_code(self):
3131
:returns: The country code.
3232
:rtype: str
3333
"""
34-
return (countrycodes.country_code(self.country) or countrycodes.default_code).upper()
34+
return (countries.country_code(self.country) or countries.default_country_code).upper()
3535

3636
@property
3737
def country_population(self):

app/services/location/jhu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ...coordinates import Coordinates
88
from ...location import TimelinedLocation
99
from ...timeline import Timeline
10-
from ...utils import countrycodes
10+
from ...utils import countries
1111
from ...utils import date as date_util
1212
from . import LocationService
1313

@@ -80,7 +80,7 @@ def get_category(category):
8080
{
8181
# General info.
8282
"country": country,
83-
"country_code": countrycodes.country_code(country),
83+
"country_code": countries.country_code(country),
8484
"province": item["Province/State"],
8585
# Coordinates.
8686
"coordinates": {"lat": item["Lat"], "long": item["Long"],},
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
LOGGER = logging.getLogger(__name__)
55

66
# Default country code.
7-
default_code = "XX"
7+
default_country_code = "XX"
88

99
# Mapping of country names to alpha-2 codes according to
1010
# https://en.wikipedia.org/wiki/ISO_3166-1.
1111
# As a reference see also https://github.com/TakahikoKawasaki/nv-i18n (in Java)
1212
# fmt: off
13-
is_3166_1 = {
13+
country_name__country_code = {
1414
"Afghanistan" : "AF",
1515
"Åland Islands" : "AX",
1616
"Albania" : "AL",
@@ -269,13 +269,13 @@
269269
"Iraq-Saudi Arabia Neutral Zone" : "XE",
270270
"Spratly Islands" : "XS",
271271

272-
# TODO "Disputed Territory" conflicts with `default_code`
272+
# TODO "Disputed Territory" conflicts with `default_country_code`
273273
# "Disputed Territory" : "XX",
274274
}
275275

276276
# Mapping of alternative names, spelling, typos to the names of countries used
277277
# by the ISO 3166-1 norm
278-
synonyms = {
278+
country_alias__country_name = {
279279
"Mainland China" : "China",
280280
"Czechia" : "Czech Republic",
281281
"Channel Islands" : "United Kingdom",
@@ -372,16 +372,15 @@ def country_code(country):
372372
Return two letter country code (Alpha-2) according to https://en.wikipedia.org/wiki/ISO_3166-1
373373
Defaults to "XX".
374374
"""
375-
# Look in synonyms if not found.
376-
if not country in is_3166_1 and country in synonyms:
377-
country = synonyms[country]
375+
if not country in country_name__country_code and country in country_alias__country_name:
376+
country = country_alias__country_name[country]
378377

379378
# Get country or fallback to default_code.
380-
country_code = is_3166_1.get(country, default_code)
379+
country_code = country_name__country_code.get(country, default_country_code)
381380

382381
# Default picked?
383-
if country_code == default_code:
384-
LOGGER.warning(f"No country_code found for '{country}'. Using '{country_code}'!")
382+
if country_code == default_country_code:
383+
LOGGER.warning(f"No country code found for '{country}'. Using '{country_code}'!")
385384

386385
# Return.
387386
return country_code

app/utils/populations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import requests
66
from cachetools import TTLCache, cached
77

8-
from .countrycodes import country_code
8+
from .countries import country_code
99

1010
LOGGER = logging.getLogger(__name__)
1111

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from app.utils import countrycodes
3+
from app.utils import countries
44

55

66
"""
@@ -18,13 +18,13 @@
1818
("BlaBla", "XX"),
1919
],
2020
)
21-
def test_countrycodes_is_3166_1(country_name, expected_country_code):
22-
assert countrycodes.country_code(country_name) == expected_country_code
21+
def test_countries_country_name__country_code(country_name, expected_country_code):
22+
assert countries.country_code(country_name) == expected_country_code
2323

2424

2525
@pytest.mark.parametrize(
26-
"country_name_synonym, expected_country_code",
26+
"country_name_alias, expected_country_code",
2727
[("Deutschland", "DE"), ("Iran (Islamic Republic of)", "IR"), ("British Virgin Islands", "VG")],
2828
)
29-
def test_countrycodes_synonym(country_name_synonym, expected_country_code):
30-
assert countrycodes.country_code(country_name_synonym) == expected_country_code
29+
def test_country_name_alias(country_name_alias, expected_country_code):
30+
assert countries.country_code(country_name_alias) == expected_country_code

0 commit comments

Comments
 (0)