Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Users\\Miguel\\AppData\\Local\\Programs\\Python\\Python39\\python.exe"
}
28 changes: 18 additions & 10 deletions COVID19Py/covid19.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ def getLocationByCountryCode(self, country_code, timelines=False) -> List[Dict]:
:return: A list of areas that correspond to the country_code. If the country_code is invalid, it returns an empty list.
"""
data = None
if timelines:
data = self._request("/v2/locations", {"country_code": country_code, "timelines": str(timelines).lower()})
else:
data = self._request("/v2/locations", {"country_code": country_code})
data = timeline(country_code, timelines)

return data["locations"]

def getLocationByCountry(self, country, timelines=False) -> List[Dict]:
Expand All @@ -143,16 +141,26 @@ def getLocationByCountry(self, country, timelines=False) -> List[Dict]:
:return: A list of areas that correspond to the country name. If the country is invalid, it returns an empty list.
"""
data = None
if timelines:
data = self._request("/v2/locations", {"country": country, "timelines": str(timelines).lower()})
else:
data = self._request("/v2/locations", {"country": country})
data = timeline(country, timelines)

return data["locations"]

def getLocationById(self, country_id: int):
def getLocationById(self, country_id: int, timelines=False):
"""
:param country_id: Country Id, an int
:return: A dictionary with case information for the specified location.
"""
data = self._request("/v2/locations/" + str(country_id))
data = timeline(country_id, timelines)
return data["location"]

def timeline(self, country_info, timelines) -> List[Dict]:
if (isinstance(country_info, int)):
data = self._request("/v2/locations/" + str(country_info))
elif (isinstance(country_ info, str)) :
if timelines:
data = self._request("/v2/locations", {"country": country_info, "timelines": str(timelines).lower()})
else:
data = self._request("/v2/locations", {"country": country_info})
else :
data = None