add traewelling integration

This commit is contained in:
Daniella / Tove 2024-10-22 18:24:54 +02:00
parent e7e1e04d56
commit 5e0acac0bb
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
2 changed files with 35 additions and 4 deletions

View file

@ -40,6 +40,7 @@ in
tcpdump
hyfetch
libreoffice
(import ./traewelling.script.nix)
] ++ (with pkgs; [
freecad
nheko
@ -89,14 +90,14 @@ in
echo "> Your TODOs from ~/sync/todo.txt:"
set_color brblue
cat ~/sync/todo.txt
set_color normal
echo
else
set_color red
echo "> Sync is not mounted."
set_color normal
echo
end
# check träwelling
traewelling
set_color normal
echo
end
function edit-todo
hx ~/sync/todo.txt

30
traewelling.script.nix Normal file
View file

@ -0,0 +1,30 @@
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
json="$(curl -s "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)"
echo "bahn.expert: https://bahn.expert/details/$(j .train.lineName | sed -E 's/(.*?) .*/\1/g')%20$(j .train.journeyNumber)"
fi
''