Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fixed parse_history function
  • Loading branch information
staging-devin-ai-integration[bot] committed Nov 2, 2024
commit 14fba9b392adfabf18b91a9cb1a6f032bfaaaec7
15 changes: 13 additions & 2 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def get_category(category):
"country_code": countries.country_code(country),
"province": item["Province/State"],
"coordinates": {
"lat": item["Lat"],
"lat": item["Lat"],
"long": item["Long"],
},
"history": history,
Expand Down Expand Up @@ -206,13 +206,24 @@ async def get_locations():
return locations


def parse_history(key: tuple, locations: list):
def parse_history(key: tuple, locations: list, index: int = None):
"""
Helper for validating and extracting history content from
locations data based on key. Validates with the current country/province
key to make sure no index/column issue.
"""

# If index is provided, try to get location at that index first
if index is not None:
try:
location = locations[index]
if (location["country"], location["province"]) == key:
return location["history"]
return {} # Key doesn't match at specified index
except IndexError:
return {} # Index out of range

# Only search through all locations if no index was provided
for i, location in enumerate(locations):
if (location["country"], location["province"]) == key:
return location["history"]
Expand Down