Created
April 17, 2025 14:47
-
-
Save evo42/6af5d1c5a6bfe89678ab638cd8947127 to your computer and use it in GitHub Desktop.
WESTbahn Check-in Agent | Bot | CLI API
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 | |
# | |
# WESTbahn Check-in | |
# | |
# KlimaTicket Ö --> WESTbahn Ticket ID | |
tno="28259629165" | |
tcode="GR688K" | |
# - - - - Robert, the robot - - - - - | |
# seat number for Robert; for example: xx-471A | xx-271D | xx-491A | xx-591A | |
placeNumber="471A" | |
## - - - - Code & Configuration - - - - - | |
# Fahrplan | |
# 06:31 innsbruck - 11:52 wien: 411 | |
# 12:31 innsbruck - 16:52 wien: 413 | |
# 16:31 innsbruck - 20:52 wien: 417 | |
# 07:08 wien - 11:29 innsbruck: 410 | |
# 11:08 wien - 15:29 innsbruck: 412 | |
# 17:08 wien - 21:29 innsbruck: 416 | |
# Crontab: Live Check-in | |
# 10 7 * * * bash /root/WESTbahnBot/checkin.bot.sh 410 >> /root/WESTbahnBot/bot.log | |
# 30 12 * * * bash /root/WESTbahnBot/checkin.bot.sh 413 >> /root/WESTbahnBot/bot.log | |
# 10 17 * * * bash /root/WESTbahnBot/checkin.bot.sh 416 >> /root/WESTbahnBot/bot.log | |
# Ticket: `https://westbahn.at/ticketshop/ticket/index/tno/$tno/code/$tcode` | |
# Check-in: `https://westbahn.at/checkin/xx-471A` | |
# Configuration | |
trainId=0 | |
trtsid=0 | |
placeId=0 | |
placeIdNumber="x-$placeNumber" | |
placeData=0 | |
trainnumber=0 | |
pvid=0 | |
jsonPlace="{}" | |
tryCounter=0 | |
currentTime=`date +"%H:%M"` | |
currentHour=`date +"%H"` | |
currentMinute=`date +"%M"` | |
# overwrite train number from CLI argument | |
if [ "$1" != "" ]; then | |
trainNumber=$1 | |
fi | |
echo " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " | |
echo " ⇨ KlimaTicket WESTbahn+" | |
echo " ⇨ Check-in: Innsbruck ⇆ Wien #$trainNumber" | |
echo " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " | |
# Find train hardware | |
for i in {10..40} | |
do | |
placeIdNumber="$i-$placeNumber" | |
placeData=$(curl -s -X POST -d "place=$placeIdNumber" "https://westbahn.at/ticketshop/relax/load-place") | |
trainnumber=$(echo "$placeData" | jq .place.trainnumber) | |
if [[ "$trainnumber" != "null" ]]; then | |
if [[ "$trainnumber" == "\"$trainNumber\"" ]]; then | |
echo "✓ TrainId found : $i" | |
jsonPlace="$placeData" | |
trainId="$i" | |
break | |
fi | |
fi | |
if [[ "$trainId" == "0" ]]; then | |
tryCounter=$(expr "$tryCounter" + 1) | |
fi | |
done | |
if [[ "$trainId" == "0" ]]; then | |
echo "❌ Train not found." | |
exit | |
fi | |
# Ticket | |
trtsid=$(echo "$jsonPlace" | jq .place.trtsid) | |
placeId=$(echo "$jsonPlace" | jq .place.rsvplid) | |
trid=$(echo "$jsonPlace" | jq .place.trid) | |
st1=$(echo "$jsonPlace" | jq .place.stations[0].stid) | |
st2=$(echo "$jsonPlace" | jq .place.stations[-1].stid) | |
ticket=$(curl -s 'https://westbahn.at/ticketshop/relax/ticket-details' --data-raw "tno=$tno&code=$tcode&trid=$trid&place=$placeIdNumber") | |
ticketName=$(echo "$ticket" | jq .place.product_name) | |
if [[ "$ticketName" == "null" ]]; then | |
echo "❌ Ticket für Check-in nicht verfügbar." | |
else | |
pvid=$(echo "$ticket" | jq .place.pvid) | |
fi | |
# Check-in | |
checkInJson=$(curl -s 'https://westbahn.at/ticketshop/relax/check-in' -H 'user-agent: WESTapi+' --data-raw "ticket%5Bstid1%5D=1&ticket%5Bstid2%5D=42&ticket%5Btno%5D=$tno&ticket%5Bpvid%5D=$pvid&ticket%5Btnocodechar%5D=$tcode&place_to=$placeId&stid1=$st1&stid2=$st2&train=$trtsid" ) | |
checkInOk=$(echo "$checkInJson" | jq .crew_verification ) | |
checkInError=$(echo "$checkInJson" | jq .error ) | |
checkInSuccess=$(echo "$checkInJson" | jq .success ) | |
# Done! | |
echo " ✓ Place | Train: $placeIdNumber | $trainNumber x $trid" | |
echo " ✓ Ticket: ${ticketName}" | |
echo " ✓ Train: $trtsid — from: $st1 ↦ to: $st2" | |
if [[ "$checkInOk" == "false" ]]; then | |
echo "✅ Check-in erfolgreich." | |
checkIn=$(echo "$checkInJson" | jq ) | |
klimaticket_owner=$(echo "$checkInJson" | jq .place.tickets[0].klimaticket_owner ) | |
if [[ "$klimaticket_owner" != "null" ]]; then | |
echo "Hi $klimaticket_owner ☀ " | |
fi | |
exit | |
fi | |
# Error? | |
if [[ "$checkInSuccess" == "false" ]]; then | |
echo "❌ Check-in nicht erfolgreich." | |
echo "Destination: $st1 --> $st2" | |
echo "Ticket: $ticket" | |
echo "" | |
echo "$checkInError" | |
# echo "PLACE: $jsonPlace" | |
# echo "CHECKIN: $checkInJson" | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment