Skip to content

Instantly share code, notes, and snippets.

@bertptrs
Last active September 18, 2019 13:21
Show Gist options
  • Save bertptrs/3e97ac3b51674200a5214c37d3abd060 to your computer and use it in GitHub Desktop.
Save bertptrs/3e97ac3b51674200a5214c37d3abd060 to your computer and use it in GitHub Desktop.
#!/bin/bash
URL=https://isonzeinterndronken.nl/leiden/dlf/
cookiejar=$(mktemp)
request() {
curl -s -c "$cookiejar" -b "$cookiejar" "$@" "$URL"
}
cleanup() {
rm "$cookiejar"
}
csrf_token() {
request | xmllint --html --xpath "string(//input[@type='hidden']/@value)" -
}
state() {
request | xmllint --html --xpath "string(//h1/text())" -
}
update_state() {
request -d "csrfmiddlewaretoken=$(csrf_token)" -d "state=$1" -e "$URL"
}
foobar_open() {
curl -s http://isdefoobaropen.nl/ -I | grep -Fi "X-FooBar-Open: true" &>/dev/null
}
hour() {
date +%-H
}
main()
{
trap cleanup EXIT
case "$(state)" in
NUCHTER)
if [[ $(hour) -ge 17 ]] && foobar_open; then
update_state dronken
fi
;;
DRONKEN)
if [[ $(hour) -ge 7 && $(hour) -lt 13 ]]; then
update_state brak
fi
;;
BRAK)
if [[ $(hour) -ge 13 ]]; then
update_state nuchter
fi
;;
*)
echo "WTF waarom is pim $(state)" >&2
exit 1
;;
esac
echo "$(state)"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment