Created
April 11, 2021 17:35
-
-
Save amanelis/e82d5dc73f77bd0bd5bb18676aa1b238 to your computer and use it in GitHub Desktop.
A quick ruby script for checking COVID-19 Vaccine in Fremont, California
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
puts "COVID Vaccine Finder / Fremont, California" | |
page = Nokogiri::HTML(open(URL)) | |
mDiv = "body > div > div.shadow-sm.p-3.mb-4.rounded > div:nth-child(8) > div" | |
bDiv = "button" | |
while true | |
now = Time.now.strftime("%d/%m/%Y %H:%M") | |
begin | |
# If the COVID Vaccine site returns more than 7 buttons, this means | |
# the vaccine has now expanded to another group and we should be notified | |
# about it | |
if page.css(mDiv).children.search(bDiv).size > 7 | |
puts "Vaccine now available for an 8th group! [#{now}]" | |
begin | |
# Attempt to call a nested method on a nokogiri child | |
puts page.css(mDiv).children.search(bDiv).last.children[0].text | |
rescue | |
puts "...failed to parse the possible 8th child element for an expanded group" | |
end | |
system("terminal-notifier -title '💉🦠' -message 'Check Hallers! #{now}' -open #{URL}") | |
puts "\n\n" | |
else | |
puts "No expanded group found #{now}" | |
end | |
rescue => error | |
puts "Fatal error on parsing just the buttons, please investigate further" | |
puts error | |
end | |
# Let's sleep and check every hour (3600)? Or maybe every 15 minutes | |
sleep 900 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment