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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -183,23 +183,18 @@ 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
- 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 = []
196
-
197
- selected_iso_code = country_name_mapping.get(country_filter, None)
198
- if region_filter != "All/Not allocated":
199
- country_in_region = [code for code in c_list if iso_code_to_sub_region.get(code) == region_filter]
200
  else:
201
- country_in_region = c_list
202
-
203
  crs_key = metadata.get("crs_key", "").strip()
204
  # Convert crs_key to a string and remove trailing ".0"
205
  crs_key_clean = re.sub(r'\.0$', '', str(crs_key))
 
183
  end_year_val = 0
184
  else:
185
  end_year_val = 0
186
+ if country.strip().startswith("["):
187
+ try:
188
+ parsed_country = json.loads(country.replace("'", '"'))
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 = []
 
 
 
 
196
  else:
197
+ c_list = [country.strip().upper()]
 
198
  crs_key = metadata.get("crs_key", "").strip()
199
  # Convert crs_key to a string and remove trailing ".0"
200
  crs_key_clean = re.sub(r'\.0$', '', str(crs_key))