nix-setup/traewelling.script.nix

38 lines
1,010 B
Nix
Raw Permalink Normal View History

2024-10-22 18:24:54 +02:00
with import <nixpkgs> {};
pkgs.writeShellScriptBin "traewelling" ''
#!/bin/sh
function color() {
2024-10-22 22:00:12 +02:00
echo -ne "\e[38;5;$1"m
2024-10-22 18:24:54 +02:00
}
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-28 21:56:26 +01:00
json="$(curl -s $( true
#)-H "Authorization: $(cat ~/sync/traewelling.token)" $( true
)"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)"
2024-10-29 00:04:48 +01:00
echo
2024-10-22 18:24:54 +02:00
fi
''