-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovid19_not.py
43 lines (39 loc) · 1.53 KB
/
covid19_not.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
import datetime # for reading present date
import time
import requests # for retreiving coronavirus data from web
from plyer import notification # for getting notification on your PC
# let there is no data initially
covidData = None
# repeating the loop for multiple times
while (True):
try:
covidData = requests.get("https://corona-rest-api.herokuapp.com/Api/india")
except:
# if the data is not fetched due to lack of internet
print("Please! Check your internet connection")
# if we fetched data
if (covidData != None):
# converting data into JSON format
data = covidData.json()['Success']
notification.notify(
# title of the notification,
title="COVID19 Stats on {}".format(datetime.date.today()),
# the body of the notification
message="Total cases : {totalcases}\nToday cases : {todaycases}\nToday deaths :{todaydeaths}\n"
"Total active :{active}\nrecovered : {recovered}".format(
totalcases=data['cases'],
todaycases=data['todayCases'],
todaydeaths=data['todayDeaths'],
active=data["active"],
recovered=data['recovered']
),
# creating icon for the notification
# we need to download a icon of ico file format
app_icon="Paomedia-Small-N-Flat-Bell.ico",
# the notification stays for 50sec
timeout=50,
toast=False
)
# sleep for 4 hrs => 60*60*4 sec
# notification repeats after every 4hrs
time.sleep(60*60*4)