-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcoronavirus.py
53 lines (44 loc) · 1.68 KB
/
coronavirus.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
#For informations check : https://towardsdatascience.com/coronavirus-track-coronavirus-in-your-country-by-displaying-notification-c914b5652088
from win10toast import ToastNotifier
from bs4 import BeautifulSoup
import time
import requests
country = "Tunisia"
notification_duration = 10
refresh_time = 10 #minutes
worldmetersLink = "https://www.worldometers.info/coronavirus/"
def data_cleanup(array):
L = []
for i in array:
i = i.replace("+","")
i = i.replace("-","")
i = i.replace(",",".")
if i == "":
i = "0"
L.append(i.strip())
return L
while True:
try:
html_page = requests.get(worldmetersLink)
except requests.exceptions.RequestException as e:
print(e) #ConnectionError
continue
bs = BeautifulSoup(html_page.content, 'html.parser')
search = bs.select("div tbody tr td")
start = -1
for i in range(len(search)):
if search[i].get_text().find(country) !=-1:
start = i
break
data = []
for i in range(1,8):
try:
data = data + [search[start+i].get_text()]
except:
data = data + ["0"]
data= data_cleanup(data)
message = "Total infected = {}, New Case = {}, Total Deaths = {}, New Deaths = {}, Recovred = {}, Active Case = {}, Serious Critical = {}".format(*data)
# message = "Total infected : {}, New Case : {}, Total Deaths : {}, New Deaths : {}, Recovred : {}, Active Case : {}, Serious Critical : {}".format(*data)
toaster = ToastNotifier()
toaster.show_toast("Coronavirus {}".format(country) , message, duration = notification_duration , icon_path ="icon.ico")
time.sleep(refresh_time*60)