Created
April 28, 2022 13:34
-
-
Save thomasweitzel/25d61cc16d1f4b7aec9c008cf5efa4c7 to your computer and use it in GitHub Desktop.
Script to book a shift as soon as booking opens. Parameters need to be exact matches. No error handling.
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
#!/bin/bash | |
# Copyright 2022 Thomas Weitzel | |
# This script has some dependencies: | |
# - needs bash compatible shell (https://www.gnu.org/software/bash/) | |
# - curl (https://curl.se/) | |
# - ripgrep (https://github.com/BurntSushi/ripgrep/) | |
# Install these tools before using it | |
# Login form parameters (example) | |
sectionId="demo" # One of: covid19-oal, memmingen, allgaeu, kf-oal, demo | |
lanr7="100" | |
pwd="100" | |
# Shift parameters (example) | |
shiftType="Sitzdienst" | |
shiftLocation="Bpx Klinikum Braliensee" | |
shiftId="DRP1" | |
shiftBegin="Di 02.02.2021 18:00" | |
shiftEnd="Di 02.02.2021 22:00" | |
### DO NOT MAKE CHANGES BELOW THIS LINE! ### | |
# Base URL | |
baseUrl="https://kvdienstplan.de/kvd/page" | |
# Save cookie in file for later use | |
cookieFile="cookie.txt" | |
# Login and create cookie file | |
curl --cookie-jar $cookieFile --data-binary 'sectionId='"$sectionId"'&lanr7='"$lanr7"'&pwd='"$pwd"'&logon=logon' $baseUrl/login | |
# Wait for <ENTER> | |
echo "Logged in on `date`" | |
echo "Shift $shiftType / $shiftLocation / $shiftId / $shiftBegin / $shiftEnd" | |
read -p "Press <ENTER> within 30 minutes to book shift" | |
# Request PLAN page and extract relevant shift Id | |
uuid=$(curl --cookie $cookieFile $baseUrl/plan | rg --replace '$1' --multiline "^.*?<td>$shiftType</td><td>$shiftLocation</td><td>$shiftId</td><td>$shiftBegin</td><td>$shiftEnd</td>[</td>0-9]+(<input[^>]+>).*$" | rg --replace '$1' "^.*?value=\"([^\"]+)\".*$") | |
# Book shift | |
curl --cookie $cookieFile --data-binary 'reserve='"$uuid"'&save=save' $baseUrl/plan | rg --replace '$1' --multiline "^.*?<h1>Plan</h1>\n<p><span class=\"[^\"]+\">([^>]+)</span>.*$" | |
# Clean up cookie file | |
rm $cookieFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment