feat: ice stats display now working :3
This commit is contained in:
parent
5aeda72c0f
commit
50ef64a041
3 changed files with 38 additions and 5 deletions
|
|
@ -59,6 +59,7 @@
|
||||||
rofimoji
|
rofimoji
|
||||||
wirelesstools
|
wirelesstools
|
||||||
jq
|
jq
|
||||||
|
bc
|
||||||
|
|
||||||
# nix-tools
|
# nix-tools
|
||||||
nix-output-monitor
|
nix-output-monitor
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
exec = ./src/ice_fetch.sh;
|
exec = ./src/ice_fetch.sh;
|
||||||
exec-if = ./src/ice_presence.sh;
|
exec-if = ./src/ice_presence.sh;
|
||||||
interval = 1;
|
interval = 1;
|
||||||
tooltip = false;
|
tooltip = true;
|
||||||
return-type = "json";
|
return-type = "json";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
# Fetch the JSON data from the API
|
# Fetch the JSON data from the APIs
|
||||||
data=$(curl -s https://iceportal.de/api1/rs/status)
|
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
|
# Extract the speed value
|
||||||
speed=$(echo "$data" | jq -r '.speed')
|
speed=$(echo "$status_data" | jq -r '.speed')
|
||||||
|
|
||||||
# Check if the speed value is empty
|
# Check if the speed value is empty
|
||||||
if [ -z "$speed" ]; then
|
if [ -z "$speed" ]; then
|
||||||
|
|
@ -10,10 +11,41 @@ if [ -z "$speed" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
# Create the JSON object
|
||||||
text="${speed} km/h"
|
text="${speed} km/h"
|
||||||
alt="Current speed"
|
alt="Current speed"
|
||||||
tooltip="Current speed of the train"
|
|
||||||
class="icestats"
|
class="icestats"
|
||||||
percentage=0
|
percentage=0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue