nix-setup/traewelling.script.nix

35 lines
977 B
Nix
Raw Normal View History

2024-10-22 18:24:54 +02:00
with import <nixpkgs> {};
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
2024-10-22 18:31:32 +02:00
if ! [ -e ~/sync/traewelling.token ] ; then
exit
fi
2024-10-22 18:24:54 +02:00
2024-10-22 18:31:32 +02:00
json="$(curl -s -H "Authorization: $(cat ~/sync/traewelling.token)" "https://traewelling.de/api/v1/user/$user/statuses" | jq .data[0])"
2024-10-22 18:24:54 +02:00
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)"
echo "bahn.expert: https://bahn.expert/details/$(j .train.lineName | sed -E 's/(.*?) .*/\1/g')%20$(j .train.journeyNumber)"
fi
''