Skip to content

Instantly share code, notes, and snippets.

@rishiip
Last active Jun 3, 2021
Embed
What would you like to do?
How I made 10 line ruby script to get my 1st jab done! 🤷🏼
# District - Pune, Date - Today's date. You can modify it as per your requirement.
uri = URI.parse("https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=363&date=#{Date.today.strftime('%d-%m-%Y')}")
results = Net::HTTP.get(uri)
results = JSON.parse(results).with_indifferent_access
availability = {}
results[:centers].each do |center|
# 1st condition - Checking Age
sessions = center[:sessions].select{ |c| c[:min_age_limit] == 18 }
# 2nd condition - Checking Availability
sessions_with_availability = sessions.select{ |s| s[:available_capacity] > 0 }
# Collect date for specific pincode if there's vaccine availability
availability[center[:pincode]] = sessions_with_availability.collect{ |s| s[:date] } if sessions_with_availability.any?
end
availability
# {413102=>["10-05-2021"], 411044=>["11-05-2021"]}
@rishiip

This comment has been minimized.

Copy link
Owner Author

@rishiip rishiip commented May 11, 2021

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