-
Notifications
You must be signed in to change notification settings - Fork 0
/
covid-tracker.py
136 lines (88 loc) · 4.12 KB
/
covid-tracker.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from tkinter import *
root = Tk()
root.geometry("530x350")
root.title("Get Covid-19 Data Country Wise")
# functions which will get covid data and will show it
def show_stacked_data():
from matplotlib import pyplot as plt
from covid import Covid
import numpy as np
covid = Covid()
cases = []
confirmed = []
active = []
deaths = []
recovered = []
try:
countries = data.get()
country_names = countries.strip()
country_names = country_names.replace(" ", ",")
country_names = country_names.split(",")
for x in country_names:
cases.append(covid.get_status_by_country_name(x))
for y in cases:
confirmed.append(y["confirmed"])
active.append(y["active"])
deaths.append(y["deaths"])
recovered.append(y["recovered"])
r=list(np.add(deaths,active))
c=list(np.add(r,recovered))
plt.bar(country_names, deaths, color='black', label='Deaths')
plt.bar(country_names, active, color='blue', bottom=deaths, label='Active')
plt.bar(country_names, recovered, color='green',bottom=r, label='Recovered')
plt.bar(country_names, confirmed, color='red', bottom=c, label='Confirmed')
plt.legend()
plt.title('Current Covid Cases (Stacked Bar Graphs)')
plt.xlabel('Country Name')
plt.ylabel('Cases(in millions)')
plt.show()
except Exception as e:
data.set("Enter correct details again (or) Check your internet connection")
# -----------------------------------------------------------------------------------------------------------
def show_grouped_data():
from matplotlib import pyplot as plt
from covid import Covid
import numpy as np
covid = Covid()
cases = []
confirmed = []
active = []
deaths = []
recovered = []
try:
countries = data.get()
country_names = countries.strip()
country_names = country_names.replace(" ", ",")
country_names = country_names.split(",")
for x in country_names:
cases.append(covid.get_status_by_country_name(x))
for y in cases:
confirmed.append(y["confirmed"])
active.append(y["active"])
deaths.append(y["deaths"])
recovered.append(y["recovered"])
bar1 = np.arange(len(country_names))
bar2 = [i+0.2 for i in bar1]
bar3 = [i+0.2 for i in bar2]
bar4 = [i+0.2 for i in bar3]
plt.bar(bar1, confirmed, 0.2, color='red', label='Confirmed')
plt.bar(bar2, recovered, 0.2, color='green',label='Recovered')
plt.bar(bar3, active, 0.2, color='blue', label='Active')
plt.bar(bar4, deaths, 0.2, color='black', label='Deaths')
plt.legend()
plt.title('Current Covid Cases (Grouped Bar Graphs)')
plt.xlabel('Country Name')
plt.ylabel('Cases(in millions)')
plt.xticks(bar1+0.3,country_names)
plt.show()
except Exception as e:
data.set("Enter correct details again (or) Check your internet connection")
Label(root, text="COVID-19 Tracker", font=("Times", "30", "bold italic"),bg='black',fg='white').pack(fill=X)
Label(root, text="Enter country names:",font=('ariel' ,15,'bold')).pack(pady=20)
data = StringVar()
data.set("Seperate country names using comma or space(not both)")
entry = Entry(root, textvariable=data, font=('ariel' ,10,'bold'), width=70,bd=5).pack()
Label(root).pack()
Button(root, text="Show Data in Grouped Bar Graphs",bg='green',fg='white',font=('ariel' ,10,'bold'), command=show_grouped_data).pack(pady=20)
Button(root, text="Show Data in Stacked Bar Graphs",bg='orange',fg='black',font=('ariel' ,10,'bold'), command=show_stacked_data).pack(pady=20)
root.mainloop()