Created
May 6, 2021 20:33
-
-
Save rushout09/7dade88c51096fc7a1c327a361024068 to your computer and use it in GitHub Desktop.
Cowin Vaccine Email notification python code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import datetime | |
import smtplib | |
import time | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
# Disable 2fa and allow less secure app access on your sender's gmail account | |
# if too much work then subscribe here to get updates: https://forms.gle/cEFnEVM7nwvaXsLa6 | |
sender = '[email protected]' | |
password = 'bazzinga' | |
receivers = ['[email protected]'] | |
message = MIMEMultipart() | |
message['From'] = sender | |
message['BCC'] = ", ".join(receivers) | |
message['Subject'] = 'Cowin Slot available in your area!' | |
smtpObj = smtplib.SMTP('smtp.gmail.com', 587) | |
smtpObj.starttls() # enable security | |
smtpObj.login(sender, password) # login with mail_id and password | |
#Change Pin code as required | |
PINCODE = "395007" | |
t=0 | |
while t==0: | |
DATE = datetime.date.today() + datetime.timedelta(days=0) | |
DATE_STR = DATE.strftime("%d-%m-%Y") | |
URL = f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode={PINCODE}&date={DATE_STR}" | |
r = requests.get(url=URL) | |
data = r.json() | |
# print(data) | |
centers = data['centers'] | |
# print(PINCODE) | |
# print(DATE_STR) | |
mail_content = '' | |
for center in centers: | |
name = center['name'] | |
address = center['address'] | |
sessions = center['sessions'] | |
for session in sessions: | |
available_capacity = session['available_capacity'] | |
min_age_limit = session['min_age_limit'] | |
SESSION_DATE = session['date'] | |
if min_age_limit>=18 and available_capacity > 0: | |
mail_content = mail_content + f'Name: {name}, address: {address}, available: {available_capacity}, min_age: {min_age_limit}, date: {SESSION_DATE}\n\n' | |
# print(f"Name: {name}, address: {address}, available: {available_capacity}, min_age: {min_age_limit}") | |
if mail_content != '': | |
message.attach(MIMEText(mail_content, 'plain')) | |
text = message.as_string() | |
smtpObj.sendmail(sender, receivers, text) | |
print("Successfully sent email") | |
time.sleep(100) | |
smtpObj.quit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment