#!/usr/bin/env bash function flogin() { rm -f cookiejar.txt csrftoken.txt local authtoken authtoken="$(curl -s https://www.e-thermostaat.nl | grep -o -m 1 '/dev/null fgetcsrftoken >csrftoken.txt } function flogout() { curl -s -c cookiejar.txt -b cookiejar.txt 'https://www.e-thermostaat.nl/logout' >/dev/null rm -f cookiejar.txt csrftoken.txt } function fgetcredentials() { #credentials.txt should be something like "username password". #code currently can't handle spaces in either. cat credentials.txt } function fensurelogin() { # fgetthermpage >/dev/null #STUB curl -s -I -c cookiejar.txt -b cookiejar.txt 'https://www.e-thermostaat.nl/pages/index' | head -n 1 | grep -m 1 200 >/dev/null if test $? -ne 0; then flogin fi } function fgetthermpage() { local page while true; do page="$(curl -s -c cookiejar.txt -b cookiejar.txt 'https://www.e-thermostaat.nl/pages/thermostat')" if test -z "$(grep -o -m 1 redirected <<<"$page")"; then break fi flogin done cat <<<"$page" } function fgetcsrftoken() { fgetthermpage | grep '" <<<"$page")" templateimgs="$(grep 'height="1"' <<<"$images")" declare -A srcalt #associative array for templateimg in $(tr -d ' ' <<<"$templateimgs"); do src="$(sed 's/.*src="\([^"]*\)".*/\1/' <<<"$templateimg")" alt="$(sed 's/.*alt="\([^"]*\)".*/\1/' <<<"$templateimg" | tr , .)" srcalt["$src"]="$alt" done tempcontext="$(grep -C 3 '