-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (50 loc) · 1.96 KB
/
main.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import requests
import bs4
import tkinter as tk
def get_html_data(url):
data = requests.get(url)
return data
def get_covid_data():
url = "https://www.worldometers.info/coronavirus/"
html_data = get_html_data(url)
bs = bs4.BeautifulSoup(html_data.text, 'html.parser')
info_div = bs.find("div",class_="content-inner").findAll("div",id="maincounter-wrap")
all_data = ""
for block in info_div:
text=block.find("h1", class_=None).get_text()
count=block.find("span",class_=None).get_text()
all_data = all_data + text + " " + count + "\n"
return all_data
def get_country_data():
name = textfield.get()
url = "https://www.worldometers.info/coronavirus/country/"+name
html_data = get_html_data(url)
bs = bs4.BeautifulSoup(html_data.text, 'html.parser')
info_div = bs.find("div", class_="content-inner").findAll("div", id="maincounter-wrap")
all_data = ""
for i in range(3):
text = info_div[i].find("h1", class_=None).get_text()
count = info_div[i].find("span", class_=None).get_text()
all_data = all_data + text + " " + count + "\n"
mainlabel['text'] = all_data
def reload():
new_data = get_covid_data()
mainlabel['text'] = new_data
# GUI
get_covid_data()
root = tk.Tk()
root.geometry("1080x700")
root.title("Covid Tracker")
f = ("Times New Roman NN",30,"bold" )
banner = tk.PhotoImage(file="covid 19.png")
bannerlabel = tk.Label(root, image=banner)
bannerlabel.pack()
textfield = tk.Entry(root, width=30 , font=80 , bg="white")
textfield.pack()
mainlabel = tk.Label(root, text=get_covid_data(), font=f, fg="#191970")
mainlabel.pack()
gbtn = tk.Button(root, text="Get Data", relief='solid',font=f ,command=get_country_data , bg="#CAFF70", fg="black")
gbtn.pack()
rbtn = tk.Button(root, text="Reload", font=f, relief='solid', command=reload , bg="#FFA07A")
rbtn.pack()
root.mainloop()