Last active
March 2, 2021 20:01
-
-
Save dphiffer/3e26b6b15743beccf04211267b584edf to your computer and use it in GitHub Desktop.
A script to update https://twitter.com/nysvaccine
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
#!/bin/bash | |
# Checks for updates to https://am-i-eligible.covid19vaccine.health.ny.gov/ | |
# If a change is found, it emails a list of addresses and tweets about the update. | |
# | |
# Adapted from: https://gist.github.com/dphiffer/678a5e06330f6f33dfc4ed9d0bfe9edb | |
# Twitter bot: https://twitter.com/nysvaccine | |
# Edit/print this flyer: https://twitter.com/nysvaccine | |
# | |
# This version expects `t` to be installed (gem install t), which adds Ruby as a | |
# dependency. You also have to setup Twitter app stuff, which is a whole ordeal. | |
# Otherwise the same dependencies apply from the script this was adapted from; | |
# you'll need curl, jq, and for email sending to work. | |
# | |
# Edit this to email a list of people about the updates | |
email_to_list="[email 1] [email 2]" | |
email_from="[email]" | |
set -o errexit | |
set -o pipefail | |
set -o nounset | |
url="https://am-i-eligible.covid19vaccine.health.ny.gov/" | |
endpoint="https://am-i-eligible.covid19vaccine.health.ny.gov/api/list-providers" | |
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
# Check the endpoint | |
result=`curl -s "$endpoint"` | |
# Grab a list of locations | |
locations=$(echo "$result" | jq -r ".providerList[] | .providerName") | |
while IFS= read -r location; do | |
# Check whether appointments are available ("AA") | |
available=`echo "$result" | jq -r ".providerList[] | select(.providerName == \"$location\") | .availableAppointments"` | |
# Normalize the location name | |
provider_name=`echo "$result" | jq -r ".providerList[] | select(.providerName == \"$location\") | .providerName" | xargs | sed -e 's/*//g'` | |
if [ "$available" == "AA" ] ; then | |
message="✨ Vaccine appointments are available at $provider_name $url" | |
elif [ "$available" == "NAC" ] ; then | |
message="❌ No vaccine appointments are available at $provider_name." | |
else | |
echo "Could not determine availability for $location: $available" | |
exit 1 | |
fi | |
# Create a results directory | |
if [ ! -d "$dir/results" ] ; then | |
mkdir "$dir/results" | |
fi | |
result_file="$dir/results/$provider_name.txt" | |
if [ ! -f "$result_file" ] || [ $(cat "$result_file") != "$available" ] ; then | |
/usr/local/bin/t update "$message" | |
for email_to in $email_to_list ; do | |
echo "$message" | mail -a "From:$email_from" \ | |
-s "Vaccine appointments at $location" \ | |
"$email_to" | |
done | |
fi | |
if [ "$provider_name" != "" ] ; then | |
echo "$available" > "$result_file" | |
fi | |
done <<< "$locations" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment