Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Type hints, algorithmic functions should not print
Return a dict of world covid19 stats.  Move all printing into the main functions.
  • Loading branch information
cclauss authored Aug 3, 2020
commit b2682cbe37c3eb6136fb69013a6b4abeb52db00e
45 changes: 18 additions & 27 deletions web_programming/world_covid19_stats.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,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/'.
'''

def get_stats():
import requests
from bs4 import BeautifulSoup

url = "https://www.worldometers.info/coronavirus/"
import requests
from bs4 import BeautifulSoup

page = requests.get(url)
page = page.text
soup = BeautifulSoup(page, 'html.parser')

print("\033[1m" + "COVID-19 Status of the World" + "\033[0m\n")

x1 = soup.findAll('h1')
x2 = soup.findAll("div", {"class": "maincounter-number"})
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)}

for i, j in zip(x1, x2):
print(i.text, j.text)

x3 = soup.findAll("span", {"class": "panel-title"})
x4 = soup.findAll("div", {"class": "number-table-main"})

for i, j in zip(x3, x4):
_i = i.text.strip()
_j = j.text.strip()
print(_i, _j, sep = ":\n", end = "\n\n")


def main():
get_stats()

main()
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")