Last active
August 11, 2016 18:30
-
-
Save KevM/54e8e43bf1a89edd4d8ddb1a7db21d90 to your computer and use it in GitHub Desktop.
Bash script to monitor the Alamo Drafthouse calendar for changes
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
# Usage: Run script with watch to repeat this check every N seconds `watch -n 20 ./mp.sh` | |
# On macos: `brew install jq watch` | |
# Example Used for Master Pancake CYOP tickets that often go on sale and then sell out quickly. | |
rm mp*.json | |
# Download the Alamo Drafthouse calendar for Austin | |
curl -s https://feeds.drafthouse.com/adcService/showtimes.svc/calendar/0002/ > mp.json | |
# Hacky jq query to pull out the Ritz location's events for the desired week/day combinations | |
cat mp.json | jq .Calendar.Cinemas[0].Months[0].Weeks[2].Days[4] >> mp-res.json | |
cat mp.json | jq .Calendar.Cinemas[0].Months[0].Weeks[2].Days[5] >> mp-res.json | |
# See if there is a difference between the current and previous results | |
DIFF=$(diff mp-res.json mp-res.old) | |
if [ "$DIFF" != "" ] | |
then | |
echo 'Something changed.' | |
osascript -e 'display notification "Alamo day check has a change." sound name "Frog" with title "Master Pancake"' | |
else | |
cp mp-res.json mp-res.old | |
fi | |
Instead of assuming that mp-res.old
exists test for it. if [ -f mp-res.old ]; then echo "Yup"; fi
If you wanted to always run the diff
command, even when mp-res.old
does not exist you could compare mp-res.json
against itself when you detected that mp-res.old
didn't exist.
You don't need to pipe mp.json
into jq
, just use the command-line interface provided.
jq .Calendar.Cinemas[0].Months[0].Weeks[2].Days[4] mp.json >> mp-res.json
jq .Calendar.Cinemas[0].Months[0].Weeks[2].Days[5] mp.json >> mp-res.json
Furthermore, if you overwrote instead of appended the output from the first command you could drop the rm mp*.json
step.
jq .Calendar.Cinemas[0].Months[0].Weeks[2].Days[4] mp.json > mp-res.json
jq .Calendar.Cinemas[0].Months[0].Weeks[2].Days[5] mp.json >> mp-res.json
I'm not that familiar with scripting on OSX. Your use of osascript
is cool! I didn't know how to do that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a pump priming problem where when the
.old
file is not present this will likely error. I hacked around that by manually creating themp-res.old
file. Maybe atouch mp-res.old
command at the start and just put up with an initial false positive?