Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -284,17 +284,19 @@ def get_country_name_and_region_mapping(_client, collection_name, region_df):
|
|
284 |
country_set = set()
|
285 |
for res in results[0] + results[1]:
|
286 |
country = res.payload.get('metadata', {}).get('country', "[]")
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
|
|
|
|
298 |
country_name_to_code = {}
|
299 |
iso_code_to_sub_region = {}
|
300 |
for code in country_set:
|
@@ -490,10 +492,14 @@ else:
|
|
490 |
total_volume = metadata.get('total_volume', "Unknown")
|
491 |
formatted_project_budget = format_currency(total_project)
|
492 |
formatted_total_volume = format_currency(total_volume)
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
|
|
|
|
|
|
|
|
497 |
matched_country = []
|
498 |
for code in c_list:
|
499 |
if len(code) == 2:
|
|
|
284 |
country_set = set()
|
285 |
for res in results[0] + results[1]:
|
286 |
country = res.payload.get('metadata', {}).get('country', "[]")
|
287 |
+
if country.strip().startswith("["):
|
288 |
+
try:
|
289 |
+
parsed_country = json.loads(country.replace("'", '"'))
|
290 |
+
if isinstance(parsed_country, str):
|
291 |
+
country_list = [parsed_country]
|
292 |
+
else:
|
293 |
+
country_list = parsed_country
|
294 |
+
except json.JSONDecodeError:
|
295 |
+
country_list = []
|
296 |
+
else:
|
297 |
+
country_list = [country.strip()]
|
298 |
+
two_digit_codes = [code.upper() for code in country_list if len(code) == 2]
|
299 |
+
country_set.update(two_digit_codes)
|
300 |
country_name_to_code = {}
|
301 |
iso_code_to_sub_region = {}
|
302 |
for code in country_set:
|
|
|
492 |
total_volume = metadata.get('total_volume', "Unknown")
|
493 |
formatted_project_budget = format_currency(total_project)
|
494 |
formatted_total_volume = format_currency(total_volume)
|
495 |
+
country_value = metadata.get('country', "").strip()
|
496 |
+
if country_value.startswith("["):
|
497 |
+
try:
|
498 |
+
c_list = json.loads(country_value.replace("'", '"'))
|
499 |
+
except json.JSONDecodeError:
|
500 |
+
c_list = []
|
501 |
+
else:
|
502 |
+
c_list = [country_value]
|
503 |
matched_country = []
|
504 |
for code in c_list:
|
505 |
if len(code) == 2:
|