Skip to content

Commit 14101de

Browse files
committed
adds country_in_database function to countrycodes
1 parent 90c0fd8 commit 14101de

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

app/utils/countrycodes.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from itertools import chain
2+
13
# Default country code.
24
default_code = "XX"
35

@@ -359,7 +361,7 @@
359361
# "Cruise Ship" has no mapping, i.e. the default val is used
360362
}
361363

362-
def country_code(country):
364+
def country_code(country, verbose=True):
363365
"""
364366
Return two letter country code (Alpha-2) according to https://en.wikipedia.org/wiki/ISO_3166-1
365367
Defaults to "XX".
@@ -371,5 +373,15 @@ def country_code(country):
371373
synonym = synonyms[country]
372374
return is_3166_1[synonym]
373375
else:
374-
print ("No country_code found for '" + country + "'. Using '" + default_code + "'")
376+
if verbose:
377+
print ("No country_code found for '" + country + "'. Using '" + default_code + "'")
375378
return default_code
379+
380+
def country_in_database(country):
381+
"""
382+
Checks if a given country is in the database.
383+
"""
384+
if country in chain(is_3166_1, synonyms):
385+
return True
386+
else:
387+
return False

0 commit comments

Comments
 (0)