Skip to content

Instantly share code, notes, and snippets.

@rishiip
Last active June 3, 2021 04:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rishiip/ad17d2dd3a6c0f98f31be04105804d94 to your computer and use it in GitHub Desktop.
Save rishiip/ad17d2dd3a6c0f98f31be04105804d94 to your computer and use it in GitHub Desktop.
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
Copy link
Author

rishiip commented May 11, 2021

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