mirror of
https://github.com/truroshan/py-cowin-termux
synced 2025-04-21 01:34:35 +05:30
Update
This commit is contained in:
parent
ce3b925890
commit
5f17e441b9
75
cowin.py
75
cowin.py
|
@ -9,34 +9,46 @@ import re
|
||||||
cowin = CoWinAPI()
|
cowin = CoWinAPI()
|
||||||
scheduler = BlockingScheduler()
|
scheduler = BlockingScheduler()
|
||||||
|
|
||||||
|
def line_break():
|
||||||
|
print("-"*25)
|
||||||
|
|
||||||
|
def clear_screen():
|
||||||
|
os.system("clear")
|
||||||
|
|
||||||
def notify():
|
def notify():
|
||||||
available_centers = cowin.get_availability_by_pincode(PINCODE,min_age_limt=AGE)
|
available_centers = cowin.get_availability_by_pincode(PINCODE,min_age_limt=AGE)
|
||||||
|
|
||||||
AVAILABLE = False
|
|
||||||
for center in available_centers.get('centers',[]):
|
for center in available_centers.get('centers',[]):
|
||||||
for session in center.get('sessions'):
|
|
||||||
capacity = session.get('available_capacity')
|
|
||||||
center_name = center.get('name')
|
|
||||||
session_date = session.get('date')
|
|
||||||
if capacity != 0 and center.get('center_id') in CENTER_ID:
|
|
||||||
|
|
||||||
MSG = f'{capacity} slots left [{session_date}] @ {center_name} ({PINCODE})'
|
for session in center.get('sessions')[1:]: # Starting from Next Day
|
||||||
|
|
||||||
|
center_name = center.get('name')
|
||||||
|
center_id = center.get('center_id')
|
||||||
|
|
||||||
|
capacity = session.get('available_capacity')
|
||||||
|
session_date = session.get('date')
|
||||||
|
vaccine_name = session.get('vaccine')
|
||||||
|
|
||||||
|
if capacity != 0 and center_id in CENTER_ID:
|
||||||
|
|
||||||
|
MSG = f'💉 {capacity} #{vaccine_name} / {session_date} / {center_name} 📍{PINCODE}'
|
||||||
|
|
||||||
# Send Notification via Termux:API App
|
# Send Notification via Termux:API App
|
||||||
os.system(f"termux-notification --content '{MSG}'")
|
os.system(f"termux-notification --content '{MSG}'")
|
||||||
AVAILABLE = True
|
|
||||||
|
CENTER_ID.remove(center_id)
|
||||||
|
|
||||||
# When last Checked
|
# When last Checked
|
||||||
print("Last Checked ⌛️ : " + datetime.now().strftime("%H:%M:%S"))
|
print("Last Checked ✅ : " + datetime.now().strftime("%H:%M:%S") + " 🕐")
|
||||||
sys.stdout.write("\033[F")
|
sys.stdout.write("\033[F")
|
||||||
|
|
||||||
# Stop Scheduler
|
# when CENTER_ID list is empty Stop Scheduler
|
||||||
if AVAILABLE:
|
if not CENTER_ID:
|
||||||
print("Shutting Down CoWin Script 👩💻 ")
|
print("Shutting Down CoWin Script 👩💻 ")
|
||||||
scheduler.shutdown(wait=False)
|
scheduler.shutdown(wait=False)
|
||||||
|
|
||||||
|
|
||||||
def main(pincode, age = 45,time = 1):
|
def main(pincode, age = 18,time = 1):
|
||||||
|
|
||||||
if age < 18 :
|
if age < 18 :
|
||||||
print("Age is less than 18.")
|
print("Age is less than 18.")
|
||||||
|
@ -47,46 +59,57 @@ def main(pincode, age = 45,time = 1):
|
||||||
available_centers = cowin.get_availability_by_pincode(str(pincode),min_age_limt=age)
|
available_centers = cowin.get_availability_by_pincode(str(pincode),min_age_limt=age)
|
||||||
|
|
||||||
CENTERS = {}
|
CENTERS = {}
|
||||||
|
INDEX_S = []
|
||||||
|
|
||||||
print("Select Vaccination Center 🏥 :")
|
print(f"Select Vaccination Center ({pincode}) 💉 \n")
|
||||||
for index,center in enumerate(available_centers.get('centers',[]),start=1):
|
for index,center in enumerate(available_centers.get('centers',[]),start=1):
|
||||||
print(f'{index} : {center.get("name")}')
|
print(f'{index} : {center.get("name")}')
|
||||||
CENTERS[index] = center.get('center_id')
|
CENTERS[index] = center.get('center_id')
|
||||||
|
|
||||||
|
INDEX_S.append(index)
|
||||||
|
|
||||||
|
print()
|
||||||
|
|
||||||
global CENTER_ID, AGE, PINCODE
|
global CENTER_ID, AGE, PINCODE
|
||||||
|
|
||||||
print("-"*20)
|
line_break()
|
||||||
print("Enter Multiple Value with Space. \n(Example : 1 2 3 4)")
|
print("""
|
||||||
print("-"*20)
|
* Select One Center
|
||||||
|
input : 1
|
||||||
|
* Select Mutiple with Space
|
||||||
|
input : 1 2 3 4
|
||||||
|
* Select All Center
|
||||||
|
Hit Enter without Input\n""")
|
||||||
|
|
||||||
INDEX_S = input("Enter Index's : ")
|
line_break()
|
||||||
|
|
||||||
INDEX_S = re.findall("(\d)",INDEX_S)
|
input_index = input("Enter Index's : ")
|
||||||
|
|
||||||
|
if input_index != '':
|
||||||
|
INDEX_S = re.findall("(\d)",input_index)
|
||||||
|
|
||||||
|
clear_screen()
|
||||||
|
|
||||||
CENTER_ID = []
|
CENTER_ID = []
|
||||||
for index in INDEX_S:
|
for index in INDEX_S:
|
||||||
if CENTERS.get(int(index)):
|
if CENTERS.get(int(index)):
|
||||||
CENTER_ID.append(CENTERS.get(int(index)))
|
CENTER_ID.append(CENTERS.get(int(index)))
|
||||||
|
|
||||||
if not INDEX_S or not CENTER_ID:
|
|
||||||
print("No Index Selected\n Program exited.")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
AGE, PINCODE = age,str(pincode)
|
AGE, PINCODE = age,str(pincode)
|
||||||
|
|
||||||
os.system("clear")
|
clear_screen()
|
||||||
|
|
||||||
scheduler.add_job(notify, 'cron',hour = "10-22", minute = f'0-59/{time}')
|
|
||||||
|
|
||||||
|
scheduler.add_job(notify, 'cron',hour = "8-22", minute = f'0-59/{time}')
|
||||||
|
print(f" 📍 {PINCODE} 💉 {AGE}+ ⌛️ {time} Minute")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
clear_screen()
|
||||||
|
|
||||||
fire.Fire(main)
|
fire.Fire(main)
|
||||||
|
|
||||||
print("CoWin Slot Checker 💉 ..")
|
print("CoWin Slot Checking 🔃\nfor Tomorrow and Day After 📆 ...")
|
||||||
|
line_break()
|
||||||
|
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
|
|
Loading…
Reference in a new issue