Update for OTP fetching using Database

This commit is contained in:
roShan 2021-05-24 19:42:08 +05:30 committed by GitHub
parent e26d9ae240
commit 6d57827a46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,4 @@
from apscheduler.schedulers.blocking import BlockingScheduler from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.schedulers import SchedulerNotRunningError
from fake_useragent import UserAgent from fake_useragent import UserAgent
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from datetime import datetime from datetime import datetime
@ -14,6 +13,12 @@ import sys
import re import re
import os import os
OTP_SITE_URL = None
'''
Add Worker Domain here example : https://db.domain.workers.dev
Check this : https://github.com/truroshan/CloudflareCoWinDB
'''
ua = UserAgent() ua = UserAgent()
scheduler = BlockingScheduler() scheduler = BlockingScheduler()
@ -23,7 +28,7 @@ def clear_screen(): os.system("clear")
class CoWinBook(): class CoWinBook():
def __init__(self,mobile_no,pincode,age,dose): def __init__(self,mobile_no,pincode,age,dose,otp):
self.mobile_no = str(mobile_no) self.mobile_no = str(mobile_no)
self.pincode = pincode # Area Pincode self.pincode = pincode # Area Pincode
self.center_id = [] # Selected Vaccination Centers self.center_id = [] # Selected Vaccination Centers
@ -37,6 +42,9 @@ class CoWinBook():
# Dose 1 or Dose 2 ( default : 1) # Dose 1 or Dose 2 ( default : 1)
self.dose = dose self.dose = dose
# OTP Fetching method
self.otp = otp
# User Age 18 or 45 # User Age 18 or 45
self.age = age self.age = age
@ -124,16 +132,24 @@ class CoWinBook():
# Request for OTP # Request for OTP
def get_otp(self): def get_otp(self):
print("OTP Sent 📲 ... ") otp_fetching_mode = ""
if self.otp == 'a':
otp_fetching_mode = 'AutoMode'
if self.otp == 's':
otp_fetching_mode = 'SiteMode'
else:
otp_fetching_mode = "ManualMode"
print(f"OTP Sent ({otp_fetching_mode}) 📲 ... ")
otp = "" otp = ""
try: try:
curr_msg = self.get_last_msg().get("body") curr_msg = self.get_msg().get("body")
for i in reversed(range(15)): for i in reversed(range(15)):
last_msg = self.get_last_msg().get("body") last_msg = self.get_msg().get("body",'')
print(f'Waiting for OTP {i} sec') print(f'Waiting for OTP {i} sec')
sys.stdout.write("\033[F") sys.stdout.write("\033[F")
@ -143,28 +159,48 @@ class CoWinBook():
print("\nOTP Recieved : ",otp) print("\nOTP Recieved : ",otp)
break break
time.sleep(2) time.sleep(3)
except Exception as e:
print(e)
# Press Ctrl + C to Enter OTP Manually
except KeyboardInterrupt:
otp = input("\nEnter OTP Manually : ")
finally:
if not otp: otp = input("\nEnter OTP : ") if not otp: otp = input("\nEnter OTP : ")
return hashlib.sha256(otp.encode('utf-8')).hexdigest() return hashlib.sha256(otp.encode('utf-8')).hexdigest()
# Get Mobile last msg for otp Checking # Get Mobile last msg for otp Checking
def get_last_msg(self): def get_msg(self):
msg = {}
# Get OTP using Termux:API v0.31
if self.otp == 'a':
msg = subprocess.Popen( msg = subprocess.Popen(
'termux-sms-list -l 1', ' ',
stdin=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,shell=True).communicate()[0].decode('utf-8') stderr=subprocess.PIPE,shell=True).communicate()[0].decode('utf-8')
try: try:
if msg != '':
msg = json.loads(msg)[0] msg = json.loads(msg)[0]
return msg return msg
except KeyError: finally:
raise Exception("Install Termux:API 0.31 Version ") raise Exception("Install Termux:API v0.31")
# Get OTP using DB hosted on Cloudflare and Attached with https://play.google.com/store/apps/details?id=com.gawk.smsforwarder
elif self.otp == 's':
if OTP_SITE_URL is None:
raise Exception("First Setup DB on Cloudflare \nhttps://github.com/truroshan/CloudflareCoWinDB ")
res = requests.get(f"{OTP_SITE_URL}/{self.mobile_no}",timeout=3).json()
if res.get("status"):
msg['body'] = res.get('data').get("message")
requests.delete(f"{OTP_SITE_URL}/{self.mobile_no}")
return msg
# Lastly enter OTP Manually
raise Exception
# Request for Current Slot Deatails ( Private Request ) # Request for Current Slot Deatails ( Private Request )
def request_slot(self): def request_slot(self):
@ -387,7 +423,7 @@ class CoWinBook():
self.user_id = USER_ID self.user_id = USER_ID
def main(mobile_no,pincode, age = 18,dose = 1,time = 30,fast = None): def main(mobile_no,pincode, age = 18,dose = 1,time = 30,otp = 'a'):
# Correct Age # Correct Age
age = 18 if age < 45 else 45 age = 18 if age < 45 else 45
@ -396,12 +432,7 @@ def main(mobile_no,pincode, age = 18,dose = 1,time = 30,fast = None):
time = 30 if time > 30 else time time = 30 if time > 30 else time
global cowin global cowin
cowin = CoWinBook(mobile_no,pincode,age,dose) cowin = CoWinBook(mobile_no,pincode,age,dose,otp)
try:
if fast:cowin.book_now()
except SchedulerNotRunningError: return
scheduler.add_job(cowin.book_now, 'cron', second = f'*/{time}') scheduler.add_job(cowin.book_now, 'cron', second = f'*/{time}')
print(f" 📍 {pincode} 💉 {age}+ ⌛️ {time} Seconds") print(f" 📍 {pincode} 💉 {age}+ ⌛️ {time} Seconds")