annikwag commited on
Commit
7fe45cb
·
verified ·
1 Parent(s): 51e8f19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -187,14 +187,14 @@ def filter_results(results, country_filter, region_filter, end_year_range, crs_f
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))
@@ -435,9 +435,10 @@ else:
435
  c_list = [country_value]
436
  matched_country = []
437
  for code in c_list:
438
- if len(code) == 2:
439
- resolved_name = get_country_name(code.upper(), region_df)
440
- if resolved_name.upper() != code.upper():
 
441
  matched_country.append(resolved_name)
442
  crs_key = metadata.get("crs_key", "").strip()
443
  # Convert to string and remove trailing ".0"
@@ -518,9 +519,10 @@ else:
518
  c_list = [country_value]
519
  matched_country = []
520
  for code in c_list:
521
- if len(code) == 2:
522
- resolved_name = get_country_name(code.upper(), region_df)
523
- if resolved_name.upper() != code.upper():
 
524
  matched_country.append(resolved_name)
525
  crs_key = metadata.get("crs_key", "").strip()
526
  # Convert to string and remove trailing ".0"
 
187
  try:
188
  parsed_country = json.loads(country.replace("'", '"'))
189
  if isinstance(parsed_country, str):
190
+ country_list = [parsed_country]
191
  else:
192
+ country_list = parsed_country
193
+ c_list = [clean_country_code(code) for code in country_list if len(clean_country_code(code)) == 2]
194
  except json.JSONDecodeError:
195
  c_list = []
196
  else:
197
+ c_list = [clean_country_code(country)]
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))
 
435
  c_list = [country_value]
436
  matched_country = []
437
  for code in c_list:
438
+ cleaned = clean_country_code(code)
439
+ if len(cleaned) == 2:
440
+ resolved_name = get_country_name(cleaned, region_df)
441
+ if resolved_name.upper() != cleaned.upper():
442
  matched_country.append(resolved_name)
443
  crs_key = metadata.get("crs_key", "").strip()
444
  # Convert to string and remove trailing ".0"
 
519
  c_list = [country_value]
520
  matched_country = []
521
  for code in c_list:
522
+ cleaned = clean_country_code(code)
523
+ if len(cleaned) == 2:
524
+ resolved_name = get_country_name(cleaned, region_df)
525
+ if resolved_name.upper() != cleaned.upper():
526
  matched_country.append(resolved_name)
527
  crs_key = metadata.get("crs_key", "").strip()
528
  # Convert to string and remove trailing ".0"