Skip to content

Commit 8e7aded

Browse files
World covid19 stats (#2271)
* Josephus problem in Python Added the code for the josephus problem in python using circular linked lists. * Update josephus_problem.py * Added World covid19 stats in web programming * Delete josephus_problem.py * Type hints, algorithmic functions should not print Return a dict of world covid19 stats. Move all printing into the main functions. * Update world_covid19_stats.py * Update world_covid19_stats.py Co-authored-by: Christian Clauss <[email protected]>
1 parent b2e8672 commit 8e7aded

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: web_programming/world_covid19_stats.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
'''
4+
Provide the current worldwide COVID-19 statistics.
5+
This data is being scrapped from 'https://www.worldometers.info/coronavirus/'.
6+
'''
7+
8+
import requests
9+
from bs4 import BeautifulSoup
10+
11+
12+
def world_covid19_stats(url: str = "https://www.worldometers.info/coronavirus") -> dict:
13+
"""
14+
Return a dict of current worldwide COVID-19 statistics
15+
"""
16+
soup = BeautifulSoup(requests.get(url).text, 'html.parser')
17+
keys = soup.findAll('h1')
18+
values = soup.findAll("div", {"class": "maincounter-number"})
19+
keys += soup.findAll("span", {"class": "panel-title"})
20+
values += soup.findAll("div", {"class": "number-table-main"})
21+
return {key.text.strip(): value.text.strip() for key, value in zip(keys, values)}
22+
23+
24+
if __name__ == "__main__":
25+
print("\033[1m" + "COVID-19 Status of the World" + "\033[0m\n")
26+
for key, value in world_covid19_stats().items():
27+
print(f"{key}\n{value}\n")

0 commit comments

Comments
 (0)