nix-setup/traewelling.script.nix
2025-10-30 10:25:53 +01:00

47 lines
1.4 KiB
Nix

{ pkgs }:
pkgs.writeShellScriptBin "traewelling" ''
#!/bin/sh
function color() {
echo -ne "\e[38;5;$1"m
}
function j() {
jq -r "$1" <<< "$json"
}
user=tudbut
if ! [ "$1" = "" ] ; then
user="$1"
fi
#if ! [ -e ~/sync/traewelling.token ] ; then
# exit
#fi
json="$(curl -s $( true
#)-H "Authorization: $(cat ~/sync/traewelling.token)" $( true
)"https://traewelling.de/api/v1/user/$user/statuses" | jq .data[0])"
if [ "$(($(date -d "$(j .train.destination.arrival)" +%s) - $(date +%s) ))" -gt 0 ] ; then
color 9
echo "> Traewelling"
color 4
echo "In train $(j .train.lineName) to $(j .train.destination.name)"
echo "Arrival: in $(
date -d "@$(( $(date -d "$(j .train.destination.arrival)" +%s) - $(date +%s) - 60 * 60))" +%H:%M
) at $(j .train.destination.rilIdentifier) $(j '.train.destination.arrivalPlatformReal // .train.destination.arrivalPlatformPlanned')"
trainkind="$(j .train.lineName | sed -E 's/(.*?) .*/\1/g')"
if [ $(j .train.operator.id) = 2449 ] ; then
trainkind=ME
fi
echo "bahn.expert: https://bahn.expert/details/$trainkind%20$(j .train.journeyNumber)/$(j .train.origin.departure)?evaNumberAlongRoute=$(j .train.origin.evaIdentifier)"
echo
else
color 9
echo "> Traewelling"
color 6
echo "Do you want to check in from $(j .train.destination.name)? https://traewelling.de/stationboard?stationId=$(j .train.destination.id)&stationName=$(j .train.destination.name | sed -e 's/ /+/g')"
echo
fi
''