Added ICE polybar module

This commit is contained in:
marc committed 2023-11-21 14:51:15 +01:00
1 parent ad76fdf575
commit f95a9948a6
4 files changed
+46 -1

No files matched your search

+1 -1
View File
@@ -51,4 +51,4 @@ bottom = false
modules-left = spotify
modules-center = date
modules-right = i3-mode
modules-right = ice i3-mode
+4
View File
@@ -55,3 +55,7 @@ fg = ${colour-scheme.base0C}
[colours/spotify]
bg = ${colour-scheme.base00}
fg = ${colour-scheme.base0A}
[colours/ice]
bg = ${colour-scheme.base00}
fg = ${colour-scheme.base0A}
+8
View File
@@ -0,0 +1,8 @@
[module/ice]
type = custom/script
exec = ~/.config/polybar/scripts/ice.sh
interval = 5
format-background = ${colours/ice.bg}
format-foreground = ${colours/ice.fg}
format-padding = 1
+33
View File
@@ -0,0 +1,33 @@
#!/bin/sh
# Show current train speed on ICE
main() {
status=$(curl -X GET https://iceportal.de/api1/rs/status 2>/dev/null)
tripInfo=$(curl -X GET https://iceportal.de/api1/rs/tripInfo/trip 2>/dev/null)
if [[ -z $status || -z $tripInfo ]]; then
return
fi
# Speed
speed=$(echo $status | jq ".speed")
# Next stop
nextId=$(echo $tripInfo | jq ".trip.stopInfo.actualNext")
nextStop=$(echo $tripInfo | jq ".trip.stops[] | select( .station.evaNr == $nextId )")
nextStopName=$(echo $nextStop | jq -r ".station.name")
nextStopArrival=$(echo $nextStop | jq ".timetable.actualArrivalTime")
nextStopRemainingSeconds=$(expr $(expr $nextStopArrival / 1000) - $(date +%s))
if [[ ${nextStopRemainingSeconds:0:1} == "-" ]]; then
nextStopRemainingTime="Arribada!"
else
nextStopRemainingTime=$(date -d@$nextStopRemainingSeconds -u +%Hh%Mm%Ss)
fi
echo "$nextStopName ·  $nextStopRemainingTime · 󰓅 $speed km/h"
}
main "$@"