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