-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountry_codes.py
More file actions
35 lines (29 loc) · 1.24 KB
/
country_codes.py
File metadata and controls
35 lines (29 loc) · 1.24 KB
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
"""a Module created to generat the 2-digit country code"""
from pygal_maps_world.i18n import COUNTRIES
# Dictionary for correcting country names
def get_country_code(country_name):
"""Return the pygal 2-digit country code for the country name."""
name_fixes = {
"Bolivia": "Bolivia, Plurinational State of",
"Brunei": "Brunei Darussalam",
"Democratic Republic of the Congo": "Congo, the Democratic Republic of the",
"Ivory Coast": "Côte d'Ivoire",
"Laos": "Lao People's Democratic Republic",
"Moldova": "Moldova, Republic of",
"North Korea": "Korea, Democratic People's Republic of",
"South Korea": "Korea, Republic of",
"Russia": "Russian Federation",
"Syria": "Syrian Arab Republic",
"Tanzania": "Tanzania, United Republic of",
"Vatican City": "Holy See",
"Vietnam": "Viet Nam",
"Republic of the Congo": "Congo",
"Palestine": "Palestinian Territory",
}
# Fix country names
country_name = name_fixes.get(country_name, country_name)
# Match with Pygal's country codes
for code, name in COUNTRIES.items():
if name.lower() == country_name.lower():
return code
return None # If no match is found