From 5e0acac0bb8b7a343bc4d77b66ecf684e39f3a79 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Tue, 22 Oct 2024 18:24:54 +0200 Subject: [PATCH] add traewelling integration --- home.nix | 9 +++++---- traewelling.script.nix | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 traewelling.script.nix diff --git a/home.nix b/home.nix index bccae38..2d0805d 100644 --- a/home.nix +++ b/home.nix @@ -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 diff --git a/traewelling.script.nix b/traewelling.script.nix new file mode 100644 index 0000000..4d1d170 --- /dev/null +++ b/traewelling.script.nix @@ -0,0 +1,30 @@ +with import {}; + +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 +'' +