Select Vaccine Type pass --v vacc_name
Book Today slot by passing -b
This commit is contained in:
parent
4fe11bf8d4
commit
56314dfc27
103
cowin.py
103
cowin.py
|
@ -26,28 +26,50 @@ def clear_screen(): os.system("clear")
|
||||||
|
|
||||||
class CoWinBook():
|
class CoWinBook():
|
||||||
|
|
||||||
def __init__(self,mobile_no,pin,age,dose,otp):
|
def init(
|
||||||
|
self,
|
||||||
|
mobile_no,
|
||||||
|
pin = "Not Passed",
|
||||||
|
age = 18 ,
|
||||||
|
vaccine = "ANY",
|
||||||
|
dose = 1,
|
||||||
|
otp = 'a',
|
||||||
|
time = 30,
|
||||||
|
bookToday = 1,
|
||||||
|
relogin = None ):
|
||||||
|
|
||||||
self.mobile_no = str(mobile_no)
|
self.mobile_no = str(mobile_no)
|
||||||
|
if relogin and os.path.exists(self.mobile_no): os.remove(self.mobile_no)
|
||||||
|
|
||||||
|
# Cron Time
|
||||||
|
global TIME
|
||||||
|
TIME = time
|
||||||
|
|
||||||
|
# Include today session for Booking Slot
|
||||||
|
self.bookToday = 0 if bookToday is True else 1
|
||||||
|
|
||||||
|
|
||||||
self.center_id = [] # Selected Vaccination Centers
|
self.center_id = [] # Selected Vaccination Centers
|
||||||
self.user_id = [] # Selected Users for Vaccination
|
self.user_id = [] # Selected Users for Vaccination
|
||||||
|
|
||||||
# Vaccination Center id and Session id for Slot Booking
|
# Vaccination Center id and Session id for Slot Booking
|
||||||
|
self.vaccine = vaccine.upper()
|
||||||
self.vacc_center = None
|
self.vacc_center = None
|
||||||
self.vacc_session = None
|
self.vacc_session = None
|
||||||
self.slot_time = None
|
self.slot_time = None
|
||||||
|
|
||||||
# Dose 1 or Dose 2 ( default : 1)
|
# Dose 1 or Dose 2 ( default : 1)
|
||||||
self.dose = dose
|
self.dose = 2 if dose >= 2 else 1
|
||||||
|
|
||||||
# OTP Fetching method
|
# OTP Fetching method
|
||||||
self.otp = otp
|
self.otp = otp
|
||||||
|
|
||||||
# User Age 18 or 45
|
# User Age 18 or 45
|
||||||
self.age = age
|
self.age = 18 if age < 45 else 45
|
||||||
|
|
||||||
# Request Session
|
# Request Session
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
|
self.requestStatus = None
|
||||||
|
|
||||||
# Data for sending request
|
# Data for sending request
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
@ -71,9 +93,11 @@ class CoWinBook():
|
||||||
# Selecting Center and User
|
# Selecting Center and User
|
||||||
self.setup_details()
|
self.setup_details()
|
||||||
|
|
||||||
print(f" 📍 {self.pin} 💉 {age}+ ⌛️ {timeInSec} Seconds")
|
bottomBanner = "for Today and Day After 📆 ..." if self.bookToday == 0 else "for Tomorrow and Day After 📆 ..."
|
||||||
|
print(f" 📍 {self.pin} 💉 {age}+ ⌛️ {TIME} Seconds")
|
||||||
|
print(f" 📲 xxxx{self.mobile_no[7:]} 💉 {self.vaccine} (Dose :{self.dose})")
|
||||||
|
print(f"CoWin Auto Slot Booking 🔃\n{bottomBanner}")
|
||||||
|
line_break()
|
||||||
|
|
||||||
# Set Header in self.session = requests.Session()
|
# Set Header in self.session = requests.Session()
|
||||||
def set_headers(self):
|
def set_headers(self):
|
||||||
|
@ -99,6 +123,7 @@ class CoWinBook():
|
||||||
|
|
||||||
# Get Token saved in file for relogin and use
|
# Get Token saved in file for relogin and use
|
||||||
def getSession(self):
|
def getSession(self):
|
||||||
|
|
||||||
self.set_headers()
|
self.set_headers()
|
||||||
try:
|
try:
|
||||||
with open(self.mobile_no, "r") as f:
|
with open(self.mobile_no, "r") as f:
|
||||||
|
@ -110,6 +135,14 @@ class CoWinBook():
|
||||||
except (FileNotFoundError,json.decoder.JSONDecodeError):
|
except (FileNotFoundError,json.decoder.JSONDecodeError):
|
||||||
self.login_cowin()
|
self.login_cowin()
|
||||||
|
|
||||||
|
def checkToken(self):
|
||||||
|
# Pause job of Checking Slot
|
||||||
|
scheduler.pause_job('slot')
|
||||||
|
|
||||||
|
self.getSession()
|
||||||
|
|
||||||
|
# Resume job of Checking Slot
|
||||||
|
scheduler.resume_job('slot')
|
||||||
|
|
||||||
# Login to selfregistration.cowin.gov.in/
|
# Login to selfregistration.cowin.gov.in/
|
||||||
def login_cowin(self):
|
def login_cowin(self):
|
||||||
|
@ -159,7 +192,7 @@ class CoWinBook():
|
||||||
try:
|
try:
|
||||||
curr_msg = self.get_msg().get("body")
|
curr_msg = self.get_msg().get("body")
|
||||||
|
|
||||||
for i in reversed(range(15)):
|
for i in reversed(range(30)):
|
||||||
|
|
||||||
last_msg = self.get_msg().get("body",'')
|
last_msg = self.get_msg().get("body",'')
|
||||||
|
|
||||||
|
@ -171,8 +204,8 @@ class CoWinBook():
|
||||||
print("\nOTP Recieved : ",otp)
|
print("\nOTP Recieved : ",otp)
|
||||||
break
|
break
|
||||||
|
|
||||||
time.sleep(3)
|
time.sleep(1)
|
||||||
except Exception as e:
|
except (Exception,KeyboardInterrupt) as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
if not otp: otp = input("\nEnter OTP : ")
|
if not otp: otp = input("\nEnter OTP : ")
|
||||||
|
@ -220,11 +253,13 @@ class CoWinBook():
|
||||||
else: # Check by District
|
else: # Check by District
|
||||||
response = self.session.get(f'https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id={self.pin}&date={todayDate}')
|
response = self.session.get(f'https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id={self.pin}&date={todayDate}')
|
||||||
|
|
||||||
|
self.requestStatus = response.status_code
|
||||||
|
|
||||||
if response.ok:
|
if response.ok:
|
||||||
self.check_slot(response.json())
|
self.check_slot(response.json())
|
||||||
elif response.status_code == 401:
|
elif response.status_code == 401:
|
||||||
print("Re-login Account : " + datetime.now().strftime("%H:%M:%S") + " 🤳")
|
print("Re-login Account : " + datetime.now().strftime("%H:%M:%S") + " 🤳")
|
||||||
self.login_cowin()
|
self.checkToken()
|
||||||
self.request_slot()
|
self.request_slot()
|
||||||
|
|
||||||
# Check Slot availability
|
# Check Slot availability
|
||||||
|
@ -232,7 +267,7 @@ class CoWinBook():
|
||||||
|
|
||||||
for center in response.get('centers',[]):
|
for center in response.get('centers',[]):
|
||||||
|
|
||||||
for session in center.get('sessions')[1:]: # Starting from Next Day
|
for session in center.get('sessions')[self.bookToday:]:
|
||||||
|
|
||||||
self.vacc_center = center.get('center_id')
|
self.vacc_center = center.get('center_id')
|
||||||
self.vacc_session = session.get("session_id")
|
self.vacc_session = session.get("session_id")
|
||||||
|
@ -242,9 +277,13 @@ class CoWinBook():
|
||||||
capacity = session.get(f'available_capacity_dose{self.dose}')
|
capacity = session.get(f'available_capacity_dose{self.dose}')
|
||||||
session_date = session.get('date')
|
session_date = session.get('date')
|
||||||
|
|
||||||
vaccine_name = session.get('vaccine')
|
vaccine_name = session.get('vaccine') + "ANY"
|
||||||
|
|
||||||
|
if capacity > 1 and \
|
||||||
|
self.vaccine in vaccine_name and \
|
||||||
|
session.get('min_age_limit') == self.age and \
|
||||||
|
center.get('center_id') in self.center_id:
|
||||||
|
|
||||||
if session.get('min_age_limit') == self.age and capacity > 1 and center.get('center_id') in self.center_id:
|
|
||||||
MSG = f'💉 {capacity} #{vaccine_name} / {session_date} / {center_name} 📍{self.pin}'
|
MSG = f'💉 {capacity} #{vaccine_name} / {session_date} / {center_name} 📍{self.pin}'
|
||||||
|
|
||||||
# Send Notification via Termux:API App
|
# Send Notification via Termux:API App
|
||||||
|
@ -257,7 +296,7 @@ class CoWinBook():
|
||||||
return
|
return
|
||||||
|
|
||||||
# When last Checked
|
# When last Checked
|
||||||
print("Last Checked ✅ : " + datetime.now().strftime("%H:%M:%S") + " 🕐")
|
print(f"Last Checked ✅ : " + datetime.now().strftime("%H:%M:%S") + " 🕐")
|
||||||
sys.stdout.write("\033[F")
|
sys.stdout.write("\033[F")
|
||||||
|
|
||||||
# Get Solved Captcha in String
|
# Get Solved Captcha in String
|
||||||
|
@ -466,38 +505,18 @@ class CoWinBook():
|
||||||
self.user_id = USER_ID
|
self.user_id = USER_ID
|
||||||
|
|
||||||
|
|
||||||
def main(mobile_no,pin = None, age = None,dose = None,otp = None,time = 30):
|
|
||||||
|
|
||||||
# Correct Age
|
|
||||||
if age is None:
|
|
||||||
age = 18
|
|
||||||
else:
|
|
||||||
age = 18 if age < 45 else 45
|
|
||||||
|
|
||||||
# Max 30 Seconds
|
|
||||||
global timeInSec
|
|
||||||
timeInSec = 30 if time > 30 else time
|
|
||||||
|
|
||||||
global cowin
|
|
||||||
cowin = CoWinBook(
|
|
||||||
mobile_no = mobile_no,
|
|
||||||
age = age,
|
|
||||||
pin = pin or "Not passed",
|
|
||||||
dose = dose or 1,
|
|
||||||
otp = otp or 'a'
|
|
||||||
)
|
|
||||||
|
|
||||||
scheduler.add_job(cowin.book_now, 'cron', second = f'*/{timeInSec or 30}')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
clear_screen()
|
clear_screen()
|
||||||
|
|
||||||
fire.Fire(main)
|
cowin = CoWinBook()
|
||||||
|
|
||||||
print("CoWin Auto Slot Booking 🔃\nfor Tomorrow and Day After 📆 ...")
|
fire.Fire(cowin.init)
|
||||||
line_break()
|
|
||||||
|
# Check for Slot
|
||||||
|
scheduler.add_job(cowin.book_now, 'interval',id = "slot",seconds = TIME, misfire_grace_time=2)
|
||||||
|
|
||||||
|
# Check Token every 3 min
|
||||||
|
scheduler.add_job(cowin.checkToken, 'cron',id ="login", minute = f'*/3',misfire_grace_time= 30)
|
||||||
|
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
|
|
Reference in a new issue