Skip to content

Instantly share code, notes, and snippets.

@spikegrobstein
Created April 15, 2019 04:52
Show Gist options
  • Save spikegrobstein/e0b3a6d2764bee3cc6a3282cd68dd058 to your computer and use it in GitHub Desktop.
Save spikegrobstein/e0b3a6d2764bee3cc6a3282cd68dd058 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
notify::send() {
local msg="$1"
local email
email="$( email_join "${email_list[@]}" )"
curl -v \
-XPOST \
--user "api:${MAILGUN_KEY}" \
--data-urlencode "to=${email}" \
--data-urlencode "from=${email}" \
--data-urlencode "subject=${subject}" \
--data-urlencode "text=$msg" \
"${MAILGUN_URL}/messages"
}
has_movie() {
local movie="$1"
curl 'https://feeds.drafthouse.com/adcService/showtimes.svc/calendar/0801/' \
--silent \
-H 'pragma: no-cache' \
-H 'origin: https://drafthouse.com' \
-H 'accept-encoding: gzip, deflate, br' \
-H 'accept-language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3355.0 Safari/537.36' \
-H 'accept: application/json, text/plain, */*' \
-H 'cache-control: no-cache' \
-H 'authority: feeds.drafthouse.com' \
-H 'referer: https://drafthouse.com/sf/calendar/new-mission' \
-H 'dnt: 1' \
--compressed \
| grep -qoi "$movie"
}
email_join() {
local IFS=","
echo "$*"
}
# use these vars for mailgun API use
if [[ -z "$MAILGUN_URL" || -z "$MAILGUN_KEY" ]]; then
echo "no mailgun settings (MAILGUN_URL / MAILGUN_KEY)"
exit 1
fi
email_list=()
from_email="movie.notifier@spike.cx"
while getopts ':e:' opt; do
case "$opt" in
e)
email_list+=("$OPTARG")
;;
f)
from_email="$OPTARG"
;;
:)
echo "Option requires argument: -$OPTARG" >&2
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
shift "$(( OPTIND - 1 ))"
MOVIE="$1"
#email="me@spike.cx,sgrobstein@apple.com"
subject="[movie-notifier] $MOVIE is available at Alamo"
if [[ -z "$MOVIE" ]]; then
echo "Please supply a movie: $0 [ -e <email> ... ] <movie>" >&2
exit 1
fi
if [[ "${#email_list[@]}" -eq 0 ]]; then
echo "No emails specified. Please supply at least one with -e <email>" >&2
exit 1
fi
if has_movie "$MOVIE"; then
echo "Ooooh. it looks like it's there"
notify::send "It looks like $MOVIE is available for purchase: https://drafthouse.com/sf/calendar/new-mission"
else
echo "the movie ($MOVIE) is not there, yet."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment