-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.py
87 lines (52 loc) · 2.5 KB
/
mail.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
import requests
import time
import smtplib
import pprint
import pandas as pd
from requests.api import head
from requests.sessions import session
print = pprint.PrettyPrinter()
MY_EMAIL = "<your main id>"#From this mail id, the alerts will be sent
MY_PASSWORD = "<your pass>"
url_states = "https://cdn-api.co-vin.in/api/v2/admin/location/states"
url_districts = "https://cdn-api.co-vin.in/api/v2/admin/location/districts/15"
url_for_findbydist = f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByDistrict"
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
"Authorization": "auth_bear"
,"Accept-Language": "en_US"}
def send_mail(date):
with requests.session() as session:
fin_end_point = url_for_findbydist+f"?district_id={district_id}&date={date}"
response = session.get(url = fin_end_point,headers=headers)
response = response.json()
for session in response['sessions']:
#For Age not equal to 45 and capacity is above zero
if (session['min_age_limit'] != 45) & (session['available_capacity'] > 0):
message_string=f"Subject: Alert'!! \n\n Available - {session['available_capacity']} in {session['name']} on {session['date']} for the age {session['min_age_limit']} and link https://www.cowin.gov.in/home "
#Configure GMAIL settings
with smtplib.SMTP_SSL("smtp.gmail.com") as connection:
# connection.starttls()
connection.login(MY_EMAIL, MY_PASSWORD)
connection.sendmail(
from_addr=MY_EMAIL,
to_addrs=["[email protected]","[email protected]"], #for multiple receipients, add another email id after a comma in the list
msg=message_string
)
res = requests.get(url_districts,headers=headers)
district = "Ranchi"
today = time.strftime("%d-%m-%Y")
datelist = pd.date_range(today, periods=7).tolist()
re = res.json()
a=re['districts']
rp = pd.DataFrame.from_dict(a)
ind = rp['district_name'].loc[lambda x: x=='Ranchi'].index
district_id= int(rp.loc[ind]["district_id"])
print.pprint(district_id)
# import daemon
# with daemon.DaemonContext():
while True:
with requests.session() as session:
for date in datelist:
date = date.strftime("%d-%m-%Y")
send_mail(date)
time.sleep(1000)