Skip to content

Instantly share code, notes, and snippets.

@srisankethu
Created May 26, 2021 13:37
Show Gist options
  • Save srisankethu/675755c83b3e0a8291546246ee22c592 to your computer and use it in GitHub Desktop.
Save srisankethu/675755c83b3e0a8291546246ee22c592 to your computer and use it in GitHub Desktop.
Find available slots in vaccination centers near you(PIN code search)
import requests
from selenium import webdriver
def search_by(driver, key, value):
tab_buttons = driver.find_elements_by_xpath("//div[@role = 'tab']")
if(key == 'PIN'):
tab_buttons[1].click()
pin_input = driver.find_element_by_xpath("//input[@data-placeholder = 'Enter your PIN']")
pin_input.send_keys(value)
pin_search_button = driver.find_element_by_class_name("pin-search-btn")
pin_search_button.click()
def apply_filters(panel, filters_names):
filters = panel.find_elements_by_xpath("//div[@class='form-check nomargright']")
for filter_name in filters_names:
if(filter_name == "Age 18+"):
filters[0].click()
elif(filter_name == "Age 45+"):
filters[1].click()
elif(filter_name == "Covishield"):
filters[2].click()
elif(filter_name == "Covaxin"):
filters[3].click()
elif(filter_name == "Sputnik V"):
filters[4].click()
elif(filter_name == "Free"):
filters[5].click()
elif(filter_name == "Paid"):
filters[6].click()
else:
pass
def find_slots(driver, date, filters_names=[]):
results_panel = driver.find_element_by_xpath("//div[@size='12']")
apply_filters(results_panel, filters_names)
vcs_panel = results_panel.find_element_by_xpath("//div[@class='center-box']")
vcs = vcs_panel.find_elements_by_xpath("//div[@class='row ng-star-inserted']")
for vc in vcs:
vc_details = vc.find_element_by_class_name("row-disp")
vc_name = vc_details.find_element_by_tag_name("h5")
vc_slots_panel = vc.find_element_by_xpath("//ul[@class='slot-available-wrap']")
vc_slots = vc_slots_panel.find_elements_by_tag_name("li")
for vc_slot in vc_slots[:2]:
try:
available_slot = vc_slot.find_element_by_xpath("//a[@title='totalslts']")
print("Vaccination center : " + str(vc_name.text))
print("No of doses : " + str(available_slot.text))
except:
pass
if __name__=="__main__":
url = "https://www.cowin.gov.in/home"
driver = webdriver.Chrome('./chromedriver')
driver.maximize_window()
driver.get(url)
search_by(driver, "PIN", 500033) # Add your pincode here
find_slots(driver, '', ["Age 18+", "Paid"]) # Add Filters here
driver.close()
@srisankethu
Copy link
Author

Download chromedriver from here which is used by selenium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment