-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.py
More file actions
92 lines (75 loc) · 3.29 KB
/
Copy pathscript.py
File metadata and controls
92 lines (75 loc) · 3.29 KB
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
import datetime
from time import sleep
import requests
import smtplib
"""
To send email you need to follow these steps:
1. Go to your google account settings.
2. Now go to the security tab or section.
3. From there go the app passwords.
4. Now generate a password for gmail and window device.
5. Now use your email id and generated password for send mail.
"""
SMTP_EMAIL = # Add email address here.
SMTP_PASSWORD = # Add password here generated by following the above steps.
def findSlot(pincodes, age, email):
result = ""
slot_available = 0
for pincode in pincodes:
date_object = datetime.date.today()
date = f"{date_object.day}-{date_object.month}-{date_object.year}"
url = f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode={pincode}&date={date}"
payload = {}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
}
response = requests.request("GET", url, headers=headers, data=payload)
try:
if response.ok:
response_json = response.json()
if response_json["centers"]:
for center in response_json["centers"]:
for session in center["sessions"]:
if (session["min_age_limit"] <= age and session["available_capacity"] > 0):
result = result + \
f'Address: {center["address"]}\nState: {center["state_name"]}\nDistrict: {center["district_name"]}\nPincode: {center["pincode"]}\nFee Type: {center["fee_type"]}\nvaccine: {session["vaccine"]}\nslots: {session["slots"]}\nDate: {session["date"]}\nAvailable slots capacity: {session["available_capacity"]}\n\n\n'
slot_available += 1
else:
print(response.raise_for_status())
return
except Exception as e:
print(e)
return
if not slot_available:
print("No vaccination slot available currently.")
else:
send_mail(result, email)
def send_mail(info, email):
server = smtplib.SMTP("smtp.gmail.com")
server.ehlo()
server.starttls()
server.ehlo()
server.login(SMTP_EMAIL, SMTP_PASSWORD)
subject = "Slot available for vaccination"
body = f"Go to COWIN Offical Website https://www.cowin.gov.in and book a slot as fast as possible.\n\nInformation\n\n{info}"
msg = f"Subject:{subject}\n\n{body}"
server.sendmail(
SMTP_EMAIL,
email,
msg
)
print("Slot Available!! \nEmail has been sent to notify user about slot availability.")
server.quit()
def main():
print('\n\n ---After every 30-sec vaccination slots are checked for availability--- \n\n')
email = input(
"Enter your email address to get notified about the slot availability: ")
pincodes = input(
"Enter pin codes of districts separated by spaces for which you want to get notified for slot availability: ").split()
age = int(input("Enter age: "))
while (1):
findSlot(pincodes, age, email)
print("Rechecking...")
sleep(30)
if __name__ == "__main__":
main()