Skip to content

Commit 5b6823c

Browse files
author
ExpDev07
committed
Added Vatican City country code & various cleanup.
1 parent 44f4da1 commit 5b6823c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

app/data/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_data(category):
3636
# Country for this location.
3737
country = item['Country/Region']
3838

39-
# Latest data insert.
39+
# Latest data insert value.
4040
latest = list(history.values())[-1];
4141

4242
# Normalize the item and append to locations.
@@ -56,7 +56,7 @@ def get_data(category):
5656
'history': history,
5757

5858
# Latest statistic.
59-
'latest': int(latest) if latest else 0,
59+
'latest': int(latest or 0),
6060
})
6161

6262
# Latest total.

app/data/countrycodes.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
default_country_name = "XX"
1+
# Default country code.
2+
default_code = "XX"
23

4+
# Mapping of country names to alpha-2 codes.
35
is_3166_1 = {
46
"Afghanistan" : "AF",
57
"Åland Islands" : "AX",
@@ -254,7 +256,7 @@
254256

255257
# Mapping of alternative names, spelling, typos to the names of countries used
256258
# by the ISO 3166-1 norm
257-
country_name_synonyms = {
259+
synonyms = {
258260
"Mainland China" : "China",
259261
"Czechia" : "Czech Republic",
260262
"South Korea" : "Korea, Republic of",
@@ -268,6 +270,7 @@
268270
"Iran" : "Iran, Islamic Republic of",
269271
"Saint Barthelemy" : "Saint Barthélemy",
270272
"Palestine" : "Palestine, State of",
273+
"Vatican City" : "Holy See (Vatican City State)",
271274
# "Others" has no mapping
272275
}
273276

@@ -280,10 +283,9 @@ def country_code(country):
280283
if country in is_3166_1:
281284
return is_3166_1[country]
282285
else:
283-
if country in country_name_synonyms:
284-
synonym = country_name_synonyms[country]
286+
if country in synonyms:
287+
synonym = synonyms[country]
285288
return is_3166_1[synonym]
286289
else:
287-
print ("No country_code found for '" + country + "'. Using '"
288-
+default_country_name+"'")
289-
return default_country_name
290+
print ("No country_code found for '" + country + "'. Using '" + default_code + "'")
291+
return default_code

0 commit comments

Comments
 (0)