-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountry_utils.py
53 lines (46 loc) · 1.72 KB
/
country_utils.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
import re
class CountryUtils:
NAMES = {
'Bahamas': 'The Bahamas',
'Cape Verde': 'Cabo Verde',
'Congo, Democratic Republic of the': 'Democratic Republic of the Congo',
'Congo, Republic of the': 'Republic of the Congo',
'Czech Republic': 'Czechia',
'Gambia, The': 'The Gambia',
'Ivory Coast': "Côte d'Ivoire",
'Korea, North': 'North Korea',
'Korea, South': 'South Korea',
'Republic of China': 'Taiwan',
'Sahrawi Republic': 'Sahrawi Arab Democratic Republic',
'State of Palestine': 'Palestine',
'Western Sahara': 'Sahrawi Arab Democratic Republic',
'United States': 'United States of America',
'Virgin Islands, British': 'British Virgin Islands',
'Virgin Islands, United States': 'United States Virgin Islands'
}
SOV_NOTE = 'Sovereign country'
NOT_SOV_NOTE = 'Not a sovereign country'
NOTES = {
'Aruba': SOV_NOTE,
'Bermuda': NOT_SOV_NOTE,
'Cayman Islands': NOT_SOV_NOTE,
'Grenada': SOV_NOTE,
'Guyana': SOV_NOTE
}
@staticmethod
def name(country):
new_name = country
if country in CountryUtils.NAMES:
new_name = CountryUtils.NAMES[country]
elif ', the' in country.lower():
new_name = re.sub(
pattern=r'(?i)(.+), the',
repl='The \\1',
string=country
)
return new_name
@staticmethod
def notes(country):
if country in CountryUtils.NOTES:
return CountryUtils.NOTES[country]
return