Well, hello programmers, this is themidom. Today in this post you will learn how to get global Corona cases using Python. So, without any delay, how about we begin.
First, we need to import three python modules.
1) Tkinter (this is inbuild so, you don't need to download and install)
2) requests (run the command "pip install requests")
3) BeautifulSoup (run the command "pip install beautifulsoup4")
Tkinter is used for making a little GUI, and whereas requests and BeautifulSoup is used to scrape the data, from news.google.com
first, we will make a simple UI, as well as we are going to write logic to run the script.
from tkinter import *
import datetime
import requests
from bs4 import BeautifulSoup
class main:
def __init__(self):
self.res = requests.get(
'https://news.google.com/covid19/map?hl=en-PH&gl=PH&ceid=PH:en')
soup = BeautifulSoup(self.res.text, 'html.parser')
link = soup.select(".UvMayb")
covid_list = []
for a in link:
covid_list.append(a.text.strip())
now = datetime.datetime.now()
current_time = now.strftime("%H:%M:%S %D")
self.window = Tk()
self.window.title("COVID-19 CORONAVIRUS PANDEMIC")
self.window.geometry("360x230")
self.label_title = Label(self.window, text="Worldwide",
font=("verdana", 20))
self.label_title.place(x=100, y=18)
# Label Total
self.label_title = Label(
self.window, text="Total:", font=("Arial", 15))
self.label_title.place(x=60, y=60)
self.label_title = Label(self.window, text=covid_list[0],
font=("Arial", 15), fg="white",
bg="yellow")
self.label_title.place(x=180, y=60)
# Label Recovered
self.label_title = Label(self.window, text="Recovered:",
font=("Arial", 15))
self.label_title.place(x=60, y=90)
self.label_title = Label(self.window, text=covid_list[1],
font=("Arial", 15), fg="white",
bg="blue")
self.label_title.place(x=180, y=90)
# Label Deaths
self.label_title = Label(self.window, text="Deaths:",
font=("Arial", 15))
self.label_title.place(x=60, y=120)
self.label_title = Label(self.window, text=covid_list[2],
font=("Arial", 15), fg="red",
bg="black")
self.label_title.place(x=180, y=120)
self.button_quit = Button(self.window, text="Quit",
command=self.window.quit)
self.button_quit.place(x=290, y=165)
self.window.mainloop()
main()
And we are done, we will get an interface like this, --Themidom