bombardier-gif / covid-vaccine-booking

This very basic script can be used to automate COVID-19 vaccination slot booking on India's Co-WIN Platform.
375 stars 216 forks source link

[NEW FEATURE ] [ #336

Closed sumit7 closed 3 years ago

sumit7 commented 3 years ago

OCR otp reading from https://messages.google.com/web. I wrote the code for myself. If people think it is needed I can commit it.

bombardier-gif commented 3 years ago

Hi @sumit7 Thanks for the idea. How would it benefit over the current AI assisted auto captcha?

siddharthgoyal90 commented 3 years ago

Hi @bombardier-gif In last week's version of the code, when the script asked for Captcha automation, I had to provide the key for the anti-captcha service, which I bought and worked fine.. However, with the latest commit of code, the script does not ask for any key even though it asks for do you want to automate captcha.. does that mean the script uses any open source services for this and no paid key is required?

ithihasmadala commented 3 years ago

Now it's an AI assisted captcha

siddharthgoyal90 commented 3 years ago

@ithihasmadala @bombardier-gif - Thanks. Does that have a better accuracy than the paid service? Just wanted to leverage the paid service in case that's more accurate? Any thoughts? OR does the current one is more preferred one to use?

ithihasmadala commented 3 years ago

I used 2captcha.com to book 15 times, and the AI assisted Captcha 8 times. I feel they are about the same...

siddharthgoyal90 commented 3 years ago

Thanks @ithihasmadala - In case I want to continue using the anti-captcha service with the latest version of code, is that doable? If yes how? (As I mentioned latest one do not ask for the API key for anti-captcha service). And the previous version of code break at OTP validation, so I am kind of stucked.

ithihasmadala commented 3 years ago

The simplest way to do it is to replace the captcha_builder_auto() in src/captcha.py with:

from anticaptchaofficial.imagecaptcha import imagecaptcha

def captcha_builder_auto(resp):
    with open('captcha.svg', 'w') as f:
        f.write(re.sub('(<path d=)(.*?)(fill=\"none\"/>)', '', resp['captcha']))

    drawing = svg2rlg('captcha.svg')
    renderPM.drawToFile(drawing, "captcha.png", fmt="PNG")

        solver = imagecaptcha()
        solver.set_verbose(1)
        solver.set_key(INSERT_API_KEY)
        captcha_text = solver.solve_and_return_solution("captcha.png")

    if captcha_text != 0:
        print(f"Captcha text: {captcha_text}")
    else:
        print(f"Task finished with error: {solver.error_code}")

    return captcha_text

Paste your API key instead of INSERT_API_KEY

I havent tested it yet. Let me know if that works.

shailesh commented 3 years ago

@bombardier-gif this is more about syncing OTP nothing to do with captcha. I guess.

https://messages.google.com/web/authentication

shailesh commented 3 years ago

this will break because a lot of people use google message app in android but some do not like MI and other phones have there owned messaging app. so I guess APK for now is awesome to sync OTP

Kanchangk commented 3 years ago

OCR otp reading from https://messages.google.com/web. I wrote the code for myself. If people think it is needed I can commit it.

can you share the code for people who want to automate the OTP but don't want to use third party apps?

sumit7 commented 3 years ago

OCR otp reading from https://messages.google.com/web. I wrote the code for myself. If people think it is needed I can commit it.

can you share the code for people who want to automate the OTP but don't want to use third party apps?

I will share the code. In short I keep taking screenshots, crop to a predetermined box and use pytesseract module for image to text conversion

saurabh1069 commented 3 years ago

i have been doing something similar before with selenium , but its more error prone, something https://messages.google.com/web. stop syncing with mobile in my xiomi phone. i like better with kvdb.io

chrome_options = Options() chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")

chrome_driver = "D:/covid-vaccine-booking-main/chromedriver.exe"
driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)

print(f"Opening URl Messages.google.com..")
driver.get("https://messages.google.com/web/conversations/2")
print(f"Waiting for 15 second..")
time.sleep(15)
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.XPATH, '/html/body/mw-app/mw-bootstrap/div/main/mw'
                                                '-main-container/div/mw-main-nav/mws'
                                                '-conversations-list/nav/div[ '
                                                '1]/mws-conversation-list-item[1]/a')))
select_Message = driver.find_element_by_xpath(
    '/html/body/mw-app/mw-bootstrap/div/main/mw-main-container/div/mw-main-nav/mws-conversations-list/nav/div['
    '1]/mws-conversation-list-item[1]/a')
select_Message.click()
select_Message.click()
text = driver.find_element_by_partial_link_text('Your OTP to register/access CoWIN')
m = re.search(r"[a-z0-9]*\d[a-z0-9]*", text.text)
OTP = m.group(0)
print(f"OTP Found as {OTP}..")
o = text.text.split("\n")
p = o[len(o) - 1]
q = p.replace(" min", "")
print(f"Message Received Time is {q}:Min Ago...")
if q.isdigit():
    if int(q) <= 3:
        print(f"Returning Validated OTP..")
        return OTP
elif q == 'Now':
    print(f"Returning Validated OTP..")
    return OTP
else:
    print(f"Returning Dummy OTP..")
    return "809607"