forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworld_covid19_stats.py
27 lines (21 loc) · 960 Bytes
/
world_covid19_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3
'''
This programs gives the latest statistics related to the situaion of Covid 19 all around the world.
The data is being scrapped from 'https://www.worldometers.info/coronavirus/'.
'''
import requests
from bs4 import BeautifulSoup
def world_covid19_stats(url: str="https://www.worldometers.info/coronavirus/") -> dict:
"""
Return a dict of world covid19 stats
"""
soup = BeautifulSoup(requests.get(url).text, 'html.parser')
keys = soup.findAll('h1')
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")