annikwag commited on
Commit
6e434e7
·
verified ·
1 Parent(s): c4930f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
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
- try:
288
- parsed_country = json.loads(country.replace("'", '"'))
289
- # If the parsed result is a string (not a list), wrap it in a list.
290
- if isinstance(parsed_country, str):
291
- country_list = [parsed_country]
292
- else:
293
- country_list = parsed_country
294
- two_digit_codes = [code.upper() for code in country_list if len(code) == 2]
295
- country_set.update(two_digit_codes)
296
- except json.JSONDecodeError:
297
- pass
 
 
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
- try:
494
- c_list = json.loads(metadata.get('country', "[]").replace("'", '"'))
495
- except json.JSONDecodeError:
496
- c_list = []
 
 
 
 
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: