annikwag commited on
Commit
df6a9a4
·
verified ·
1 Parent(s): e9b7c63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -183,9 +183,13 @@ def filter_results(results, country_filter, region_filter, end_year_range, crs_f
183
  end_year_val = 0
184
  else:
185
  end_year_val = 0
186
-
187
  try:
188
- c_list = json.loads(country.replace("'", '"'))
 
 
 
 
 
189
  c_list = [code.upper() for code in c_list if len(code) == 2]
190
  except json.JSONDecodeError:
191
  c_list = []
@@ -286,7 +290,12 @@ def get_country_name_and_region_mapping(_client, collection_name, region_df):
286
  for res in results[0] + results[1]:
287
  country = res.payload.get('metadata', {}).get('country', "[]")
288
  try:
289
- country_list = json.loads(country.replace("'", '"'))
 
 
 
 
 
290
  two_digit_codes = [code.upper() for code in country_list if len(code) == 2]
291
  country_set.update(two_digit_codes)
292
  except json.JSONDecodeError:
 
183
  end_year_val = 0
184
  else:
185
  end_year_val = 0
 
186
  try:
187
+ parsed_country = json.loads(country.replace("'", '"'))
188
+ # If the parsed result is a string (not a list), wrap it in a list.
189
+ if isinstance(parsed_country, str):
190
+ c_list = [parsed_country]
191
+ else:
192
+ c_list = parsed_country
193
  c_list = [code.upper() for code in c_list if len(code) == 2]
194
  except json.JSONDecodeError:
195
  c_list = []
 
290
  for res in results[0] + results[1]:
291
  country = res.payload.get('metadata', {}).get('country', "[]")
292
  try:
293
+ parsed_country = json.loads(country.replace("'", '"'))
294
+ # If the parsed result is a string (not a list), wrap it in a list.
295
+ if isinstance(parsed_country, str):
296
+ country_list = [parsed_country]
297
+ else:
298
+ country_list = parsed_country
299
  two_digit_codes = [code.upper() for code in country_list if len(code) == 2]
300
  country_set.update(two_digit_codes)
301
  except json.JSONDecodeError: