Skip to content

samridhgupta/cowin-vaccinate-me-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Automated CoWin Slot Booking Bot

This is a fork over the neat covid-vaccine-booking. Thanks for creating a playground for me to build on 🤘

Loved the project? Please consider donating to help it improve!

Contents

Before you start

  • This is a proof of concept project. I do NOT endorse or condone, in any shape or form, automating any monitoring/booking tasks. Use at your own risk. Seriously, if you get into legal trouble for using this, I am not liable.

  • Do NOT use unless all beneficiaries selected are supposed to get the same vaccine and dose.

  • No option to register new user or add beneficiaries. This can be used only after beneficiary has been added through the official app/site

  • Be careful if you choose to use the auto-book feature. It will blindly select first available center, date - both sorted ascending - and a RANDOM slot. I would recommend against using this. Only added for the convenience of people in short supply areas.

  • If you accidentally book a slot, don't worry. You can always login to the official portal and cancel that. There will be an X symbol on the right-top corner for each beneficiary.

  • The captcha is a bit buggy and you may be required to make 5-6 tries before you are able to book. (requires anti-captcha key)

  • API Details (read the first paragraph at least): https://apisetu.gov.in/public/marketplace/api/cowin/cowin-public-v2

  • If you face any issues please refer to the troubleshooting section at the end of this doc, Still I know code quality isn't great. Suggestions are welcome.

What this repository does

  1. Automates OTP read from the SMS after the token expires.
  2. Randomly chooses one of the available slots instead of waiting for input from the user. image

How it works via IFTTT app on Android

  1. https://ifttt.com/ is used to create a SMS trigger. The trigger happens when the OTP SMS is received
  2. The trigger sends the text of the SMS to a REST service, I have used a free service which needs 0 setup for a shared storage

How it works via CoWIN OTP Retriever app on Android

  1. The CoWinOTPRetriever Android app has been created to automatically read the OTP SMS and then send it to the shared storage
  2. You only need to install and start the app, enter your CoWIN registered phone number, and then start the OTP listener.

How it works via Shortcuts app on iOS

  1. Shortcuts app is used to create an SMS trigger. The trigger happens when the OTP SMS is received
  2. The trigger sends the text of the SMS to a REST service, I have used a free service which needs 0 setup for a shared storage

In Parallel

  1. The script runs continuously to poll (same logic as the original repository)
  2. Whenever the OTP expires, an OTP is requested
  3. When the OTP SMS is received on the Android, phone, the above logic triggers to store the OTP SMS in the shared storage. On iOS, when the OTP SMS is received, the above logic triggers a notification which the user has to long press and confirm after which the OTP is stored in shared storage
  4. The script polls the shared storage to get the OTP
  5. Once the OTP is received, the polling resumes
  6. If a free slot is found, rather than waiting for an input, it randomly chooses a slot and attempts to book

Setup Guide for Android

Option 1: IFTTT

  1. Create an account in ifttt.com (A premium paid account is recommended for a quicker response)

  2. Create a new applet

  3. If this..... click on Android SMS trigger

  4. Select "New SMS received matches search" and use CoWIN as the search key

  5. Then... Choose a service named Webhooks and then select make a web request

  6. Paste the url: https://kvdb.io/DVQszkcZaUwBoHwbJyEeMG/XXXXXXXXXX replace XXXXXXXXXX with your phone number

  7. Method is PUT

  8. Content Type PlainText

  9. Body: Add ingredient and select Text

  10. On your android phone, install ifttt app

  11. Login

  12. Ensure that the battery saver mode, and all other optimizations are removed. The appshould always run (This is the key for quick response).

    1. Tip: If your IFTTT is not triggered when your SMS is received: https://www.androidpolice.com/2020/05/30/how-to-prevent-apps-sleeping-in-the-background-on-android/ Also a premium account is faster
  13. Clone this repository

  14. On Mac I had to do the following too

    brew install python-tk
    brew install SoX
  15. Run the script cd src && python3 covid-vaccine-slot-booking.py

  16. Use the steps given below to enter your preferences

  17. Hopefully you get the slot

  18. Stay healthy and stay safe!

IFTTT steps in screenshots:


image


image


image


image


image


image


image


image


Now Enter URL : https://kvdb.io/DVQszkcZaUwBoHwbJyEeMG/XXXXXXXXXX & replace XXXXXXXXXX with your mobile number

Copy from below

https://kvdb.io/DVQszkcZaUwBoHwbJyEeMG/

image

Option 2: CoWIN OTP Retriever

  1. Install the CoWinOTPRetriever Android app by enabling installation from unknown sources.
  2. Follow this guide to install apps from unknown sources: https://www.verizon.com/support/knowledge-base-222186/
  3. Allow the app to run in background so that the app does not stop even if you multi-task or leave the phone idle. (Note that, there still might be some phone model specific settings and optimizations which could stop the app from running in background. Check point number 8)
  4. Grant sms access to allow the app to read CoWIN OTP sms.
  5. Enter 10 digit mobile number registered on the CoWIN portal.
  6. Switch ON the OTP Listener.
  7. If the OTP is successfully sent to the key value store, you will see the status as shown below.
  8. Ensure that the battery saver mode, and all other optimizations are removed. The app should always run (This is the key for quick response). Tip: If you don not see a success message on the app when you receive an OTP: https://www.androidpolice.com/2020/05/30/how-to-prevent-apps-sleeping-in-the-background-on-android/
  9. Security tip: Make sure to change back your settings to disallow app installation from unknown sources.

CoWIN OTP Retriever steps in screenshots

image


image


image


image


image


image


image


image


image


Now Enter Your Number on first Text Field

and

Check key on second Text Field (under KV DB Bucket Key) is same as the below mentioned else copy and paste on the field

DVQszkcZaUwBoHwbJyEeMG

image


image


image


image


image


Setup Guide for iOS

Using Shortcuts app

  1. Open the shortcuts app
  2. Tap on the + button at the top right
  3. Tap on Create Personal Automation
  4. Select the Message option
  5. Put CoWIN in the Message Contains option & leave everything blank. Tap on Next button
  6. Tap on Add action and search for the option Set Variable. Give the variable name text and input as Shortcut Input
  7. Then add another action and select `URL` and paste the url: https://kvdb.io/DVQszkcZaUwBoHwbJyEeMG/XXXXXXXXXX replace XXXXXXXXXX with your phone number
    
  8. Then add another action and select Get Contents of Url. Click on show more. Change the method to PUT. Request Body to File and in the file row tap on Choose Variable and select text which we defined in Step 6.
  9. Click Next and save this automation.
  10. Clone this repository Go to src directory and run the script cd src && python3 covid-vaccine-slot-booking.py
  11. On Mac I had to do the following too
    • brew install python-tk
    • brew install SoX
  12. Run the script, enter your phone number.
  13. Now as soon as OTP is recieved you will also get a notification from shortcuts app. Long press it and click on run. It will start OTP auto read process.
  14. Use the steps given below to enter your preferences.
  15. Now whenever the script session expires, it will send the notification described in step 13 and repeat the process to trigger OTP auto read.
  16. It is recommended that you set a different notification tone for this notification to be able to distinguish.
  17. Hopefully you get the slot
  18. Stay healthy and stay safe!

Shortcuts steps in screenshots

image1


image2


image


image


image


image


image


Now Enter URL : https://kvdb.io/DVQszkcZaUwBoHwbJyEeMG/XXXXXXXXXX & replace XXXXXXXXXX with your mobile number

Copy from below

https://kvdb.io/DVQszkcZaUwBoHwbJyEeMG/

image


image


image


image


Tips:

I used this command to run the script as it was giving me Syntax error: python3 src/covid-vaccine-slot-booking.py Also I used this command to install the dependencies python3 -m pip install -r requirements.txt

COVID-19 Vaccination Slot Booking Script

This very basic CLI based script can be used to automate covid vaccination slot booking on Co-WIN Platform.

Important:

  • POC project. Use at your own risk.
  • Do NOT use unless all beneficiaries selected are supposed to get the same vaccine and dose.
  • No option to register new user or add beneficiaries. This can be used only after beneficiary has been added through the official app/site
  • If you accidentally book a slot, don't worry. You can always login to the official portal and cancel that.
  • API Details: https://apisetu.gov.in/public/marketplace/api/cowin/cowinapi-v2
  • And finally, I know code quality probably isn't great. Suggestions are welcome.

Usage:

For the anyone not familiar with Python and using Windows, using the covid-vaccine-slot-booking.exe executable file would be the easiest way. It might trigger an anti-virus alert. That's because I used pyinstaller to package the python code and it needs a bit more effort to avoid such alerts. How to install Python

OR

Run the script file as show below:

python3 src\covid-vaccine-slot-booking.py

If you're on Linux, install the beep package before running the Python script. To install beep, run:

sudo apt-get install beep

If you already have a bearer token, you can also use:

python3 src\covid-vaccine-slot-booking.py --token=YOUR-TOKEN-HERE

Third-Party Package Dependency:

  • tabulate : For displaying data in tabular format.
  • requests : For making GET and POST requests to the API.
  • inputimeout : For creating an input with timeout.

Steps:

  1. After cloning, cd to the Folder.

  2. Install Python (How to install Python)

  3. Install all dependencies by running: pip install -r requirements.txt

  4. Run script: python3 src\covid-vaccine-slot-booking.py

  5. Select Beneficiaries. Read the important notes. You can select multiple beneficiaries by providing comma-separated index values such as 1,2:

    Enter the registered mobile number: ██████████
    Requesting OTP with mobile number ██████████..  
    Enter OTP: 999999  
    Validating OTP..  
    Token Generated: █████████████████████████████████████████████████████████████  
    Fetching registered beneficiaries..  
    +-------+----------------------------+---------------------------+------------+  
    | idx   | beneficiary_reference_id   | name                      | vaccine    |  
    +=======+============================+===========================+============+  
    | 1     | ██████████████             | █████████████████████████ | COVISHIELD |  
    +-------+----------------------------+---------------------------+------------+  
    | 2     | ██████████████             | █████████████████         |            |  
    +-------+----------------------------+---------------------------+------------+  
      
    ################# IMPORTANT NOTES #################  
    # 1. While selecting beneficiaries, make sure that selected beneficiaries are all taking the same dose: either first OR second.  
    # Please do no try to club together booking for first dose for one beneficiary and second dose for another beneficiary.  
    #  
    # 2. While selecting beneficiaries, also make sure that beneficiaries selected for second dose are all taking the same vaccine: COVISHIELD OR COVAXIN.  
    # Please do no try to club together booking for beneficiary taking COVISHIELD with beneficiary taking COVAXIN.  
    ###################################################  
      
    Enter comma separated index numbers of beneficiaries to book for : 2
    
  6. Ensure correct beneficiaries are getting selected:

    Selected beneficiaries:  
    +-------+----------------------------+-----------+  
    | idx   | beneficiary_reference_id   | vaccine   |  
    +=======+============================+===========+  
    | 1     | ██████████████             |           |  
    +-------+----------------------------+-----------+
    
  7. Select a state

    +-------+-----------------------------+  
    | idx   | state                       |  
    +=======+=============================+  
    | 1     | Andaman and Nicobar Islands |  
    +-------+-----------------------------+  
    | 2     | Andhra Pradesh              |  
    +-------+-----------------------------+
    +-------+-----------------------------+
    +-------+-----------------------------+  
    | 35    | Uttar Pradesh               |  
    +-------+-----------------------------+  
    | 36    | Uttarakhand                 |  
    +-------+-----------------------------+  
    | 37    | West Bengal                 |  
    +-------+-----------------------------+
    
    Enter State index: 18
    
  8. Select districts you are interested in. Multiple districts can be selected by providing comma-separated index values

    +-------+--------------------+  
    | idx   | district           |  
    +=======+====================+  
    | 1     | Alappuzha          |  
    +-------+--------------------+  
    | 2     | Ernakulam          |  
    +-------+--------------------+  
    | 3     | Idukki             |  
    +-------+--------------------+
    +-------+--------------------+
    +-------+--------------------+  
    | 13    | Thrissur           |  
    +-------+--------------------+  
    | 14    | Wayanad            |  
    +-------+--------------------+
    
    Enter comma separated index numbers of districts to monitor : 2,13
    
  9. Ensure correct districts are getting selected.

    Selected districts:  
    +-------+---------------+-----------------+-----------------------+  
    | idx   | district_id   | district_name   | district_alert_freq   |  
    +=======+===============+=================+=======================+  
    | 1     | 307           | Ernakulam       | 660                   |  
    +-------+---------------+-----------------+-----------------------+  
    | 2     | 303           | Thrissur        | 3080                  |  
    +-------+---------------+-----------------+-----------------------+
    
  10. Enter the minimum number of slots to be available at the center:

    Filter out centers with availability less than: 5
    
  11. Script will now start to monitor slots in these districts every 15 seconds. Note: It will ask you monitor frequency ProTip: Do not select less than 5 seconds it will bombard cowin server and will get your request blocked, create issues in OTP generation for your number. #85

    ===================================================================================  
    Centers available in Ernakulam from 01-05-2021 as of 2021-04-30 15:13:44: 0  
    Centers available in Thrissur from 01-05-2021 as of 2021-04-30 15:13:44: 0  
    No viable options. Waiting for next update in 15s.
    ===================================================================================  
    Centers available in Ernakulam from 01-05-2021 as of 2021-04-30 15:13:59: 0  
    Centers available in Thrissur from 01-05-2021 as of 2021-04-30 15:13:59: 0  
    No viable options. Waiting for next update in 15s.
    
  12. If at any stage your token becomes invalid, the script will make a beep and prompt for y or n. If you'd like to continue, provide y and proceed to allow using same mobile number

    Token is INVALID.  
    Try for a new Token? (y/n): y
    Try for OTP with mobile number ███████████? (y/n) : y
    Enter OTP: 888888
    
  13. When a center with more than minimum number of slots is available, the script will make a beep sound - different frequency for different district. It will then display the available options as table:

    ===================================================================================  
    Centers available in Ernakulam from 01-05-2021 as of 2021-04-30 15:34:19: 1  
    Centers available in Thrissur from 01-05-2021 as of 2021-04-30 15:34:19: 0  
    +-------+----------------+------------+-------------+------------+------------------------------------------------------------------------------+  
    | idx   | name           | district   | available   | date       | slots                                                                        |  
    +=======+================+============+=============+============+==============================================================================+  
    | 1     | Ayyampilly PHC | Ernakulam  | 30          | 01-05-2021 | ['09:00AM-10:00AM', '10:00AM-11:00AM', '11:00AM-12:00PM', '12:00PM-02:00PM'] |  
    +-------+----------------+------------+-------------+------------+------------------------------------------------------------------------------+  
    ---------->  Wait 10 seconds for updated options OR  
    ---------->  Enter a choice e.g: 1.4 for (1st center 4th slot): 1.3
    
  14. Before the next update, you'll have 10 seconds to provide a choice in the format centerIndex.slotIndex eg: The input1.4 will select the vaccination center in second row and its fourth slot.

How to run on windows

How to run on windows

  1. Step 1 - Download or clone this repo.

  2. Step 2 - Go to folder tests then windows exe.zip. Unzip the folder and Now run the program "captcha_tests.exe". If you see a dialog box click on quit, and you will see a Captcha. If this is what happened you are all good to go.

  3. Now come back to main folder unzip "windows exe.zip"go to this "windows exe" folder

    image-20210511140608465

    Now start the program "covid-vaccine-slot-booking.exe", you will not see any error.

  4. DO NOT DELETE ANY FOLDER OR FILE.

Troubleshooting common problems

  1. Problem 1

    Can't setFont(Times-Roman) missing the T1 files?
    Originally <class 'TypeError'>: makeT1Font() argument 2 must be str, not None
    

    Solution 1: Then run the python script directly in the src folder after installing the required modules from requirements.txt. That solved it for me

    Solution 2: If you are running ubantu(tested) or winows , this problem is due to some font files from package (reportlab) which are included in arch linux but not on ubantu. Follow these steps to install reportlab correctly. It can be done after you have installed all the requirements rom txt file.

    Solution 3: Try to perform the test first in test folder for captcha first to see if this error still there.

    Solution 4: (Recommended) Try to use this Linux executable " ./covid-vaccine-slot-booking-linux " file directly from terminal it does not require anything to install just like windows exe. Windows exe is under going testing

  2. Problem 2

    Regarding beep package - Device not found or beep not found

    Solution : Follow these steps for ubantu

    • sudo apt-get install beep #insatll this once

    • sudo modeprobe pcspkr #This will solve Device not found error

    • Testing beep is simple just type

      beep
      

      on terminal this will beep a sound from speakers.

  3. Problem 3

    SMS is not read automatically

    Solution: Check the mobile number you have entered in this step.

    image

    This number must match the number you enter while running the script.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published