diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3a2a9b6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\Miguel\\AppData\\Local\\Programs\\Python\\Python39\\python.exe" +} \ No newline at end of file diff --git a/COVID19Py/covid19.py b/COVID19Py/covid19.py index a68faa7..6ebde27 100644 --- a/COVID19Py/covid19.py +++ b/COVID19Py/covid19.py @@ -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]: @@ -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 + \ No newline at end of file