2020-08-03 06:45:53 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-08-06 15:50:23 +00:00
|
|
|
"""
|
2020-08-03 06:45:53 +00:00
|
|
|
Provide the current worldwide COVID-19 statistics.
|
|
|
|
This data is being scrapped from 'https://www.worldometers.info/coronavirus/'.
|
2020-08-06 15:50:23 +00:00
|
|
|
"""
|
2020-08-03 06:45:53 +00:00
|
|
|
|
|
|
|
import requests
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
|
|
def world_covid19_stats(url: str = "https://www.worldometers.info/coronavirus") -> dict:
|
|
|
|
"""
|
|
|
|
Return a dict of current worldwide COVID-19 statistics
|
|
|
|
"""
|
2020-08-06 15:50:23 +00:00
|
|
|
soup = BeautifulSoup(requests.get(url).text, "html.parser")
|
|
|
|
keys = soup.findAll("h1")
|
2020-08-03 06:45:53 +00:00
|
|
|
values = soup.findAll("div", {"class": "maincounter-number"})
|
|
|
|
keys += soup.findAll("span", {"class": "panel-title"})
|
|
|
|
values += soup.findAll("div", {"class": "number-table-main"})
|
|
|
|
return {key.text.strip(): value.text.strip() for key, value in zip(keys, values)}
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print("\033[1m" + "COVID-19 Status of the World" + "\033[0m\n")
|
|
|
|
for key, value in world_covid19_stats().items():
|
|
|
|
print(f"{key}\n{value}\n")
|