R wrapper for cowin API

Deepanshu Bhalla Add Comment ,
In this article you will see how you can check vaccine slots on cowin site using R programming. This article is mainly for Indian residents as cowin website is for booking vaccine slots for Indian nationals.

I developed the package which interacts with cowin API. This package was developed last month and released on Github. Unfortunately i didn't get time to write detailed documentation around it last month. This package lets you to find slots for vaccination in your district or pincode. Cowin API has restrictions - it allows maximum 100 request per 5 minutes per IP. Your IP address can be blocked if rate limit exceeds.

cowin API and R


You can install the package from github using the command below
# install.packages("devtools")
Once you are done with the installation, load the package.

Extract list of States

df.States <- extract_states()
It returns state names along with state IDs.
states.state_id	states.state_name
1	Andaman and Nicobar Islands
2	Andhra Pradesh
3	Arunachal Pradesh
4	Assam
5	Bihar
6	Chandigarh

Fetch Districts of a particular state

You need to pass state ID in the function extract_districts(state_id) State ID can be fetched from extract_states() function. In the example below, State ID 16 is for Karnataka.
df.District <- extract_districts(16)

Get Districts of all the Indian states

This function loops through all the states and fetch districts against them.
df.Districts <- extract_districts_all(df.States)

Vaccine slots for 7 days from today’s date in a given district

You need to pass District ID in the function. District ID can be obtained from extract_districts_all() function.
slots <- slots_district(df.Districts[1,1])

Vaccine slots for 7 days from today’s date in a given district

By default date is today's date. You can change it.
slots <- slots_district(df.Districts[1,1], date = Sys.Date()+7)

Cleaned Output of slots_district() and slots_pincode()

In age_limit argument, you can enter 18 for 18+, 45 for 45+. By default, combination of both
slots2 <-  slots_cleaned(slots)
slots2 <-  slots_cleaned(slots, age_limit = 45)

Vaccine slots for Multiple districts

district.ids <- c(1,3)
slots.all <- slots_district_all(district.ids)

Vaccine slots for 7 days from a specific date in a given pincode

In this function slots_pincode(pincode), you need to enter 6 digit pincode.
slots.pincodes <- slots_pincode(201301)
slots.pincodes2 <-  slots_cleaned(slots.pincodes)
slots.pincodes2 <-  slots_cleaned(slots.pincodes, age_limit = 45)

Vaccine slots for multiple pincodes

slots.all <- slots_pincode_all(pincodes = c(201301,110032))
Related Posts
Spread the Word!
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 0 Response to "R wrapper for cowin API"
Next → ← Prev