-
Notifications
You must be signed in to change notification settings - Fork 6
/
coronaV2.py
56 lines (48 loc) · 1.67 KB
/
coronaV2.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
#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 requests
import time
country = "Tunisia"
notification_duration = 10
refresh_time = 10 #minutes
data_check= []
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)
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)
if data_check != data:
data_check = data
toaster = ToastNotifier()
toaster.show_toast("Coronavirus {}".format(country) , message, duration = notification_duration , icon_path ="icon.ico")
else:
time.sleep(refresh_time*60)
continue