From 50ef64a04144134012d320f552c303d577f74c5f Mon Sep 17 00:00:00 2001 From: etwas Date: Sun, 18 May 2025 11:36:47 +0200 Subject: [PATCH] feat: ice stats display now working :3 --- home/misc_pkgs/packages.nix | 1 + home/wm/waybar/default.nix | 2 +- home/wm/waybar/src/ice_fetch.sh | 40 +++++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/home/misc_pkgs/packages.nix b/home/misc_pkgs/packages.nix index 2ebb7e8..5c5e3f8 100644 --- a/home/misc_pkgs/packages.nix +++ b/home/misc_pkgs/packages.nix @@ -59,6 +59,7 @@ rofimoji wirelesstools jq + bc # nix-tools nix-output-monitor diff --git a/home/wm/waybar/default.nix b/home/wm/waybar/default.nix index d635b54..c184eeb 100644 --- a/home/wm/waybar/default.nix +++ b/home/wm/waybar/default.nix @@ -43,7 +43,7 @@ exec = ./src/ice_fetch.sh; exec-if = ./src/ice_presence.sh; interval = 1; - tooltip = false; + tooltip = true; return-type = "json"; }; diff --git a/home/wm/waybar/src/ice_fetch.sh b/home/wm/waybar/src/ice_fetch.sh index 01cc0b1..3bf2099 100755 --- a/home/wm/waybar/src/ice_fetch.sh +++ b/home/wm/waybar/src/ice_fetch.sh @@ -1,8 +1,9 @@ -# Fetch the JSON data from the API -data=$(curl -s https://iceportal.de/api1/rs/status) +# Fetch the JSON data from the APIs +status_data=$(curl -s https://iceportal.de/api1/rs/status) +trip_data=$(curl -s https://iceportal.de/api1/rs/tripInfo/trip) # Extract the speed value -speed=$(echo "$data" | jq -r '.speed') +speed=$(echo "$status_data" | jq -r '.speed') # Check if the speed value is empty if [ -z "$speed" ]; then @@ -10,10 +11,41 @@ if [ -z "$speed" ]; then exit 1 fi +# Extract additional information for the tooltip +train_type=$(echo "$trip_data" | jq -r '.trip.trainType') +line_number=$(echo "$trip_data" | jq -r '.trip.vzn') +train_number=$(echo "$status_data" | jq -r '.tzn | gsub("ICE"; "Tz")') +train_series=$(echo "$status_data" | jq -r '.series') + +# Get next stop information +next_stop_eva=$(echo "$trip_data" | jq -r '.trip.stopInfo.actualNext') +next_stop_info=$(echo "$trip_data" | jq -r --arg eva "$next_stop_eva" '.trip.stops[] | select(.station.evaNr == $eva)') + +next_stop_name=$(echo "$next_stop_info" | jq -r '.station.name') +next_stop_arrival=$(echo "$next_stop_info" | jq -r '.timetable.actualArrivalTime') +next_stop_arrival_delay=$(echo "$next_stop_info" | jq -r '.timetable.arrivalDelay') +next_stop_distance=$(echo "$next_stop_info" | jq -r '.info.distanceFromStart') +current_position=$(echo "$trip_data" | jq -r '.trip.actualPosition') + +# Calculate distance to next stop +distance_to_next=$((next_stop_distance - current_position)) +distance_km=$(echo "scale=2; $distance_to_next/1000" | bc) + +# Convert timestamps to human-readable format +if [ "$next_stop_arrival" != "null" ]; then + next_stop_arrival_time=$(date -d @$((next_stop_arrival/1000)) +"%H:%M") +else + next_stop_arrival_time="N/A" +fi + +# Create the tooltip text +tooltip="${train_type} ${line_number} (${train_number} - Br${train_series})\n\n" +tooltip+="Next stop: ${next_stop_name}\n" +tooltip+="${next_stop_arrival_time} (${next_stop_arrival_delay}) - ${distance_km} km" + # Create the JSON object text="${speed} km/h" alt="Current speed" -tooltip="Current speed of the train" class="icestats" percentage=0