· 4 years ago · May 17, 2021, 02:14 PM
1import json
2
3import requests, time, webbrowser, datetime
4from tkinter import *
5import tkinter.messagebox
6import winsound
7import os
8
9##########--------------------------------User Input------------------------------------------------###############
10
11#pin = "712258" ### give your pin,
12age_group = "All" ### options are All, 18-44, 45+
13vaccine_preference = "NA" ### options are NA, COVAXIN, COVISHIELD
14freqency = 60 ### every XX seconds it will check
15dose = 1 ### 1 or 2
16telegram_notification = True ### True or False
17
18# install --> pip install pushbullet.py
19# install pushbullet in phone
20# Get your own api key from https://www.pushbullet.com/#settings >> access tokens
21
22# pushbullet_notification = True ### True or False
23# pushbullet_api_key = "o.XX"
24
25##################################################################################################################
26
27
28
29def agecheck(data):
30 if (age_group.lower() == "all"):
31 return True
32 elif (age_group.lower() == "18-44" and data['min_age_limit'] < 45):
33 return True
34 elif (age_group.lower() == "45+" and data['min_age_limit'] >= 45):
35 return True
36 else:
37 return False
38
39def vaccine_pref(data):
40 if (vaccine_preference.upper() == "NA"):
41 return True
42 elif (vaccine_preference.upper() == data['vaccine'].upper()):
43 return True
44 else:
45 return False
46
47## UI once vaccine is found ################################################################
48def UI(text_to_show):
49 root = tkinter.Tk()
50 root.title("Found your vaccine!!!!!!!!")
51 root.geometry('500x200')
52 l = Label(root, text = text_to_show, wraplength=300, justify="center", font="helvetica 14")
53 l.config(font =("Courier", 14))
54 l.pack()
55
56
57 def onClick():
58 webbrowser.open("https://www.cowin.gov.in/home")
59
60 button = Button(root, text="Launch Cowin Portal", command=onClick, height=5, width=30)
61
62 button.pack(side='bottom')
63 root.mainloop()
64#############################################################################################
65
66headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62',
67 'origin':'https://selfregistration.cowin.gov.in', 'origin':'https://selfregistration.cowin.gov.in/','if-none-match': "e8e1-/v8XW50+mZEvkY+V+T6pX6C6/TY",
68 'Referrer Policy': 'strict-origin-when-cross-origin', 'sec-ch-ua-mobile': '?0', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors','sec-fetch-site': 'cross-site',
69 'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiIyZjM0MzlhMi0zOGRlLTQ5ZmMtYWQzMy0wYjViN2UyM2NmY2EiLCJ1c2VyX2lkIjoiMmYzNDM5YTItMzhkZS00OWZjLWFkMzMtMGI1YjdlMjNjZmNhIiwidXNlcl90eXBlIjoiQkVORUZJQ0lBUlkiLCJtb2JpbGVfbnVtYmVyIjo5MDA3OTc0OTc3LCJiZW5lZmljaWFyeV9yZWZlcmVuY2VfaWQiOjQ1MzczNzYzOTkyMTMwLCJzZWNyZXRfa2V5IjoiYjVjYWIxNjctNzk3Ny00ZGYxLTgwMjctYTYzYWExNDRmMDRlIiwidWEiOiJNb3ppbGxhLzUuMCAoV2luZG93cyBOVCAxMC4wOyBXaW42NDsgeDY0KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTAuMC40NDMwLjIxMiBTYWZhcmkvNTM3LjM2IEVkZy85MC4wLjgxOC42MiIsImRhdGVfbW9kaWZpZWQiOiIyMDIxLTA1LTE2VDAzOjAyOjA1LjcwMFoiLCJpYXQiOjE2MjExMzQxMjUsImV4cCI6MTYyMTEzNTAyNX0.TBH9VvQNQ0Z9E2KmEmcR-VNV14fGU5LPQ7CidrOJ3GA'}
70
71vaccine_found = False
72counter = 0
73
74while vaccine_found==False:
75 os.system('cls')
76 print("Total No. of tries: " +str(counter+1) + "", end = " ")
77
78 for k in range(0,8):
79 print(".", end=" ")
80 date = datetime.date.today() + datetime.timedelta(days=k * 7)
81 #URL = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=" + pin + "&date=" + date.strftime("%d-%m-%Y")
82 URL = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=725&date=" + date.strftime(
83 "%d-%m-%Y")
84 try:
85 request = requests.get(url=URL, headers=headers)
86 request = json.loads(request.text)
87 #print(request)
88 for i in request["centers"]:
89 for j in i["sessions"]:
90 #print(j)
91 if(j['available_capacity_dose'+str(dose)] > 0):
92 if(agecheck(j)==True):
93 if(vaccine_pref(j)==True):
94 #print("!!!! Vaccine slot available in " + i["name"] + ", date: " + j["date"] + "-------------")
95 #vaccine_found = True
96 duration = 1000 # milliseconds
97 freq = 440 # Hz
98 winsound.Beep(freq, duration)
99 if(telegram_notification==True):
100 try:
101 requests.post('https://api.telegram.org/botXXXX/sendMessage?chat_id=XXXX&text='+str(j['available_capacity'])+" slot(s) available in " + i["name"] + ", pin: "+ str(i["pincode"])+", date: " + j["date"] +" for age group "+str(j['min_age_limit']))
102 # from pushbullet import Pushbullet
103 # pb = Pushbullet("o.XX")
104 # push = pb.push_note("Vaccine Slot Notification - " + (str(datetime.datetime.now())), str(j['available_capacity'])+" slot(s) available in " + i["name"] + ", pin: "+ str(i["pincode"])+", date: " + j["date"] +" for age group "+str(j['min_age_limit']))
105 # my_channel = pb.get_channel('first_dose_kolkata')
106 # push = pb.push_note("Vaccine Slot Notification - " + (str(datetime.datetime.now())), str(j['available_capacity'])+" slot(s) available in " + i["name"] + ", pin: "+ str(i["pincode"])+", date: " + j["date"] +" for age group "+str(j['min_age_limit']), channel=my_channel)
107 except:
108 print("Telegram notification issue")
109 UI(str(j['available_capacity']) + " slot(s) available in " + i["name"] + ", pin: " + str(i["pincode"]) + ", date: " + j["date"]+" for age group "+str(j['min_age_limit']))
110 except Exception as e:
111 print(e)
112 counter = counter + 1
113 print(" ")
114 print("Waiting for " + str(freqency) + " secs before trying again")
115 z = 0
116 while z < freqency:
117 print(".")
118 time.sleep(10)
119 z = z + 10
120 print(" ")
121