Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,14 +43,22 @@ def get_country_name_mapping(_client, collection_name, region_df):
|
|
43 |
countries = res.payload.get('metadata', {}).get('countries', "[]")
|
44 |
try:
|
45 |
country_list = json.loads(countries.replace("'", '"'))
|
46 |
-
|
|
|
|
|
47 |
except json.JSONDecodeError:
|
48 |
pass
|
49 |
|
50 |
-
# Create a mapping of
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
return country_name_to_code
|
53 |
|
|
|
54 |
# Get country name mapping
|
55 |
client = get_client()
|
56 |
country_name_mapping = get_country_name_mapping(client, collection_name, region_df)
|
|
|
43 |
countries = res.payload.get('metadata', {}).get('countries', "[]")
|
44 |
try:
|
45 |
country_list = json.loads(countries.replace("'", '"'))
|
46 |
+
# ADD: only add codes of length 2
|
47 |
+
two_digit_codes = [code.upper() for code in country_list if len(code) == 2]
|
48 |
+
country_set.update(two_digit_codes)
|
49 |
except json.JSONDecodeError:
|
50 |
pass
|
51 |
|
52 |
+
# Create a mapping of {CountryName -> ISO2Code}
|
53 |
+
# so you can display the name in the selectbox but store the 2-digit code
|
54 |
+
country_name_to_code = {}
|
55 |
+
for code in country_set:
|
56 |
+
name = get_country_name(code, region_df)
|
57 |
+
country_name_to_code[name] = code
|
58 |
+
|
59 |
return country_name_to_code
|
60 |
|
61 |
+
|
62 |
# Get country name mapping
|
63 |
client = get_client()
|
64 |
country_name_mapping = get_country_name_mapping(client, collection_name, region_df)
|