Spaces:
Sleeping
Sleeping
Update appStore/region_utils.py
Browse files- appStore/region_utils.py +10 -3
appStore/region_utils.py
CHANGED
@@ -6,11 +6,18 @@ import pandas as pd
|
|
6 |
def load_region_data(file_path):
|
7 |
return pd.read_csv(file_path)
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
def get_country_name(alpha2_code, region_df):
|
10 |
"""Map ISO country code to country name (case-insensitive)."""
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
|
15 |
def get_regions(region_df):
|
16 |
"""Get unique regions and sub-regions."""
|
|
|
6 |
def load_region_data(file_path):
|
7 |
return pd.read_csv(file_path)
|
8 |
|
9 |
+
def clean_country_code(code):
|
10 |
+
# Remove non-alphabetical characters and convert to uppercase.
|
11 |
+
return ''.join(filter(str.isalpha, code)).upper()
|
12 |
+
|
13 |
+
|
14 |
def get_country_name(alpha2_code, region_df):
|
15 |
"""Map ISO country code to country name (case-insensitive)."""
|
16 |
+
# Clean the code before processing.
|
17 |
+
code = clean_country_code(alpha2_code)
|
18 |
+
row = region_df[region_df['alpha-2'] == code]
|
19 |
+
return row['name'].values[0] if not row.empty else code
|
20 |
+
|
21 |
|
22 |
def get_regions(region_df):
|
23 |
"""Get unique regions and sub-regions."""
|