Skip to content

Commit c5b54a6

Browse files
committed
Merge branch 'development'
2 parents 5a97cc6 + f0c2bbb commit c5b54a6

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

app/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
)
2525

2626
# Setup CORS (https://fastapi.tiangolo.com/tutorial/cors/)
27-
# ** Note: Wild-card setup is used here for demonstration only,
28-
# Please change the setting in accordance with your application
27+
# Note: Wild-card setup is used here for demonstration only,
28+
# Please change the setting in accordance with your application
2929
app.add_middleware(
3030
CORSMiddleware,
3131
allow_origins=["*"],

app/models/covid_model_api_v2.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,16 @@ def get_country(self, country_name: str) -> Dict[str, Any]:
8686
""" Get a country data from its name or ISO 2 """
8787
all_country_data = self.get_current()['data']
8888

89+
# Check input
90+
if not isinstance(country_name, str) or not country_name.isalpha():
91+
return {}
92+
8993
# Search for a given country
90-
## In case a country name is not found, assume it's a country code (iso2)
91-
if country_name not in [country_data['location'].lower() for country_data in all_country_data]:
92-
country_name = self.lookup_table[country_name.upper()] # translate country code to its name
94+
country_name = country_name.lower()
95+
country_name_from_code = self.lookup_table.get(country_name.upper(), '').lower()
9396

94-
data = [country_data for country_data in all_country_data if country_name.lower() == country_data['location'].lower()]
95-
data = data[0] if data else data
97+
data = [country_data for country_data in all_country_data if country_data['location'].lower() in [country_name, country_name_from_code]]
98+
data = data[0] if data else {}
9699

97100
return data
98101

0 commit comments

Comments
 (0)