Last active
April 22, 2022 08:09
-
-
Save comdotlinux/38dc5f8f5fff3d3391f8eafe43f4e629 to your computer and use it in GitHub Desktop.
Munich Drivers Licence Appointment availability Checker
This file contains hidden or 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 | |
function getAppointmentInfoJson() { | |
PHP_SESSION_ID=$(curl -sSL -D - 'https://terminvereinbarung.muenchen.de/fs/termin/index.php?loc=FS' -o /dev/null | awk -F: '/Set-Cookie/{print $2}' | awk -F= '{print $2}' | awk -F\; '{print $1}') | |
curl -sSL 'https://terminvereinbarung.muenchen.de/fs/termin/index.php?loc=FS' \ | |
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \ | |
-H 'Accept-Language: en-US,en;q=0.9,hi;q=0.8,mr;q=0.7,de;q=0.6' \ | |
-H 'Cache-Control: no-cache' \ | |
-H 'Connection: keep-alive' \ | |
-H 'Content-Type: application/x-www-form-urlencoded' \ | |
-H 'DNT: 1' \ | |
-H "Cookie: PHPSESSID=${PHP_SESSION_ID}" \ | |
-H 'Origin: https://terminvereinbarung.muenchen.de' \ | |
-H 'Pragma: no-cache' \ | |
-H 'Referer: https://terminvereinbarung.muenchen.de/fs/termin/index.php?loc=FS' \ | |
-H 'Sec-Fetch-Dest: document' \ | |
-H 'Sec-Fetch-Mode: navigate' \ | |
-H 'Sec-Fetch-Site: same-origin' \ | |
-H 'Sec-Fetch-User: ?1' \ | |
-H 'Upgrade-Insecure-Requests: 1' \ | |
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36' \ | |
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"' \ | |
-H 'sec-ch-ua-mobile: ?0' \ | |
-H 'sec-ch-ua-platform: "Linux"' \ | |
--data-raw 'step=WEB_APPOINT_SEARCH_BY_CASETYPES&CASETYPES%5BFS+Internationaler+FS+beantragen%5D=0&CASETYPES%5BFS+Internationaler+FS+bei+Besitz%5D=0&CASETYPES%5BFS+Umschreibung+Ausl%C3%A4ndischer+FS%5D=1&CASETYPES%5BFS+Ersatz+PBS%5D=0&CASETYPES%5BFS+Dienstf%C3%BChrerschein+umschreiben%5D=0&CASETYPES%5BFS+Internationaler+FS+bei+Besitz%5D=0&CASETYPES%5BFS+Abholung+F%C3%BChrerschein%5D=0&CASETYPES%5BFS+Abholung+eines+Personenbef%C3%B6rderungsscheines%5D=0' \ | |
--compressed | grep jsonAppoints | awk -F= '{print $2}' | tr -d "';" | jq -c | |
} | |
function checkAndNotifyIfAppointmentIsAvailable() { | |
output_json=$(getAppointmentInfoJson) | |
anyValues=$(echo ${output_json} | jq '."Termin FS Allgemeinschalter_G".appoints | map_values(select(. | length > 0)) | length') | |
if [[ "${anyValues}" -gt 0 ]]; then | |
echo "-- Appointments available. See below --" | |
echo ${output_json} | jq | |
echo "-- --" | |
dates=$(echo ${output_json} | jq '."Termin FS Allgemeinschalter_G".appoints | map_values(select(. | length > 0))') | |
if [[ $OSTYPE == 'darwin'* ]]; then | |
osascript -e "display notification \"$dates\" with title \"Appointments Available\"" | |
elif [[ $OSTYPE == 'linux-gnu' ]] && command -v notify-send > /dev/null ; then | |
notify-send --urgency=critical "Appointments available. on $dates" | |
fi | |
else | |
echo "-- No Appointments available :( --" | |
fi | |
} | |
SLEEP_TIME=30 | |
if [[ $# -gt 0 ]] && [[ "x$1" = "x-s" || "x$1" = "x--sleep" ]]; then | |
SLEEP_TIME=$2 | |
shift 2 | |
fi | |
while true; do | |
echo "-- $(date): Checking if any appointments are available. --" | |
checkAndNotifyIfAppointmentIsAvailable | |
sleep ${SLEEP_TIME} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment