Вот еще один пример использования API вместо удаления из Википедии, в данном случае бесплатный covid19 API :
import requests
class Covid19ApiHelper:
URL_API = 'https://api.covid19api.com/summary'
def __init__(self):
self._global_info = None
self._countries = None
def refresh(self):
"""Request data from the API and saves it"""
response = requests.get(self.URL_API)
data = response.json()
self._global_info = data['Global']
self._countries = {item['CountryCode']: item for item in data['Countries']}
def get_global_info(self):
return self._global_info
def get_country_info(self, countryCode):
"""Returns the information by country using the standard two digit country code"""
return self._countries[countryCode]
if __name__=='__main__':
covid_helper = Covid19ApiHelper()
covid_helper.refresh()
print(covid_helper.get_global_info())
print(covid_helper.get_country_info('CO'))
Глобальный вывод:
{'NewConfirmed': 86850, 'TotalConfirmed': 2894581, 'NewDeaths': 5839, 'TotalDeaths': 202795, 'NewRecovered': 27616, 'TotalRecovered': 815948}
Выходные данные Колумбии:
{'Country': 'Colombia', 'CountryCode': 'CO', 'Slug': 'colombia', 'NewConfirmed': 261, 'TotalConfirmed': 5142, 'NewDeaths': 8, 'TotalDeaths': 233, 'NewRecovered':
64, 'TotalRecovered': 1067, 'Date': '2020-04-26T09:16:56Z'}
Источник данных: https://covid19api.com/#details