1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00

feat(scripts): meteo

This commit is contained in:
2021-04-07 09:45:36 +02:00
parent 4adf8fea0a
commit bd200b655d
3 changed files with 83 additions and 0 deletions

View File

@@ -119,6 +119,7 @@ in {
scripts.playlist
scripts.devanagari
scripts.betacode # ancient greek betacode to unicode converter
scripts.meteo
nur.repos.kmein.mahlzeit
# nur.repos.kmein.slide
nur.repos.kmein.vimv

View File

@@ -94,6 +94,12 @@ in rec {
name = "tag";
};
meteo = wrapScript {
packages = [ pkgs.jq pkgs.curl pkgs.xdotool pkgs.sxiv pkgs.gnused ];
script = ./meteo.sh;
name = "meteo";
};
booksplit = wrapScript {
packages = [ pkgs.ffmpeg tag ];
script = "${voidrice}/.local/bin/booksplit";

76
packages/scripts/meteo.sh Executable file
View File

@@ -0,0 +1,76 @@
#! /bin/sh
# usage: meteo --list
# usage: meteo --update
# usage: meteo STATION
set -efu
# TODO XDG
CONFIG_DIR=$HOME/.config/wetter
STATIONS_FILE=$CONFIG_DIR/stations.json
case ${1-} in
--list)
sed -n 's/^\s*\(--[^)]\+\))$/\1/p' "$0"
jq -r -n \
--slurpfile stations_file "$STATIONS_FILE" \
'
$stations_file[0] as $known_stations |
$known_stations | keys[]
'
exit
;;
--update)
mkdir -p "$(dirname "$STATIONS_FILE")"
exec >"$STATIONS_FILE"
curl -fsS http://wetterstationen.meteomedia.de/ |
jq -Rrs '
def decodeHTML:
gsub("ä";"ä") |
gsub("ö";"ö") |
gsub("ü";"ü") |
gsub("Ä";"Ä") |
gsub("Ö";"Ö") |
gsub("Ü";"Ü") |
gsub("ß";"ß")
;
[
match(".*<option value=\"/\\?map=Deutschland&station=(?<station>[0-9]+)\">(?<name>[^<]+)</option>";"g")
.captures |
map({"\(.name)":(.string)}) |
add |
{"\(.name|decodeHTML)":(.station|tonumber)}
] |
add
'
exit
;;
esac
# set -x
station=${1-103840}
station=$(jq -e -n \
--arg station "$station" \
--slurpfile stations_file "$STATIONS_FILE" \
'
$stations_file[0] as $known_stations |
$station |
if test("^[0-9]+$") then
tonumber
else
$known_stations[.]
end
')
cache="/tmp/${LOGNAME}_wetter_$station.png"
curl -sS \
"http://wetterstationen.meteomedia.de/messnetz/vorhersagegrafik/$station.png" \
-o "$cache"
if window_id=$(xdotool search --name "^sxiv - $cache$"); then
xdotool key --window "$window_id" r
else
sxiv "$cache" &
fi