Last active
July 25, 2021 05:32
-
-
Save dphiffer/678a5e06330f6f33dfc4ed9d0bfe9edb to your computer and use it in GitHub Desktop.
A script that monitors vaccine appointment availability at New York State-run providers.
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 | |
# see also: https://kvz.io/bash-best-practices.html | |
set -o errexit | |
set -o pipefail | |
set -o nounset | |
# A script to monitor updates to this web page: | |
# https://am-i-eligible.covid19vaccine.health.ny.gov/ | |
# | |
# Usage: | |
# vaccine-check.sh [location 1] [location 2] | |
# | |
# Example: | |
# vaccine-check.sh Javits Queens Brooklyn | |
# | |
# The ethics of using this script are complicated, but here is my position: you can help marginally improve | |
# the equitable distribution of the COVID vaccine in New York State by working with elders and marginalized | |
# communities who may not be able to easily monitor the website, or run a script like this. In a perfect world | |
# there would have been better communication/outreach, and a scheduling system that is easier to use. We are | |
# not in that world yet, so maybe let's look out for each other as best as we can. | |
# | |
# You may also want to consider printing out this flyer and distributing: https://tinyurl.com/nysvaccine | |
# | |
# 1. Install curl, jq, and setup mailutils and ssmtp | |
# See: https://rianjs.net/2013/08/send-email-from-linux-server-using-gmail-and-ubuntu-two-factor-authentication | |
# 2. Make sure the script can write to a './results' dir | |
# 3. Try running it: vaccine-check.sh Javits | |
# 4. Uncomment and edit the variables email_to_list and email_from to send email | |
# 5. Add this script to a cronjob: | |
# * * * * * /path/to/vaccine-check.sh > /dev/null | |
# Uncomment these vars to send email | |
# email_to_list="[email 1] [email 2]" | |
# email_from="[email from]" | |
if [ $# == 0 ] ; then | |
echo "Usage: $0 location" | |
echo " $0 \"SUNY Albany\"" | |
echo " $0 Brooklyn Queens Yonkers" | |
exit 1 | |
fi | |
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"` | |
for location in "$@" ; do | |
# Check whether appointments are available ("AA") | |
available=`echo "$result" | jq -r ".providerList[] | select(.providerName | contains(\"$location\")) | .availableAppointments" | head -n 1` | |
# Normalize the location name | |
provider_name=`echo "$result" | jq -r ".providerList[] | select(.providerName | contains(\"$location\")) | .providerName" | head -n 1 | 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 | |
message="No matches with location name '$location' (check spelling, capitalization)." | |
fi | |
# Create a results directory | |
if [ ! -d "$dir/results" ] ; then | |
mkdir "$dir/results" | |
fi | |
result_file="$dir/results/$provider_name.txt" | |
if [[ -z ${email_to_list+x} ]] ; then | |
echo "$message" | |
else | |
if [ ! -f "$result_file" ] || [ $(cat "$result_file") != "$available" ] ; then | |
# Only email if the availability changes | |
for email_to in $email_to_list ; do | |
echo "$message" | mail -a "From:$email_from" \ | |
-s "Vaccine appointments at $location" \ | |
"$email_to" | |
done | |
fi | |
fi | |
if [ "$provider_name" != "" ] ; then | |
echo "$available" > "$result_file" | |
fi | |
done |
Thanks for that @wgwz. The version of mail
I'm using, "mail (GNU Mailutils) 3.4," uses -a
for "append header." It's a shame the different versions don't standardize this type of thing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess depending on what version of
mail
you're using this script has a bug.my version:
The
mail -a
flag is used.-a
is for attachments. Doesn't make sense to attach"From:$email_form"
and it throws an error.Just get rid of that flag and everything should work assuming you've got a valid
.mailrc
configured.