From 8e7aded87f5e1aaa88bf785c60432d3258b003f5 Mon Sep 17 00:00:00 2001 From: Rayvant Sahni <38404580+rayvantsahni@users.noreply.github.com> Date: Mon, 3 Aug 2020 12:15:53 +0530 Subject: [PATCH] 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 --- web_programming/world_covid19_stats.py | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 web_programming/world_covid19_stats.py diff --git a/web_programming/world_covid19_stats.py b/web_programming/world_covid19_stats.py new file mode 100644 index 000000000..1907ed5f3 --- /dev/null +++ b/web_programming/world_covid19_stats.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +''' +Provide the current worldwide COVID-19 statistics. +This 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 current worldwide COVID-19 statistics + """ + 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")