From dfb6cce357c5332e62a39b41e4b30ac2b22b7c07 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 29 May 2022 21:46:58 +0200 Subject: l news: vorbisTools -> vorbis-tools --- lass/2configs/radio/news.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lass/2configs/radio') diff --git a/lass/2configs/radio/news.nix b/lass/2configs/radio/news.nix index 27b12409..aa10ea29 100644 --- a/lass/2configs/radio/news.nix +++ b/lass/2configs/radio/news.nix @@ -27,7 +27,7 @@ let ''; send_to_radio = pkgs.writers.writeDashBin "send_to_radio" '' - ${pkgs.vorbisTools}/bin/oggenc - | + ${pkgs.vorbis-tools}/bin/oggenc - | ${pkgs.libshout}/bin/shout --format ogg --host localhost --port 1338 --mount /live ''; -- cgit v1.2.3 From 885a068ad4a0e647cee527aabd39953ad3e238b2 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 6 Jun 2022 12:55:04 +0200 Subject: l radio: set opus bitrate to 96 kbps --- lass/2configs/radio/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lass/2configs/radio') diff --git a/lass/2configs/radio/default.nix b/lass/2configs/radio/default.nix index 0611be7c..601ef74d 100644 --- a/lass/2configs/radio/default.nix +++ b/lass/2configs/radio/default.nix @@ -165,14 +165,14 @@ in { output.icecast(mount = '/music.ogg', password = 'hackme', %vorbis(quality = 1), source) output.icecast(mount = '/music.mp3', password = 'hackme', %mp3.vbr(), source) - output.icecast(mount = '/music.opus', password = 'hackme', %opus(bitrate = 64), source) + output.icecast(mount = '/music.opus', password = 'hackme', %opus(bitrate = 96), source) extra_input = audio_to_stereo(input.harbor("live", port=1338)) o = smooth_add(normal = source, special = extra_input) output.icecast(mount = '/radio.ogg', password = 'hackme', %vorbis(quality = 1), o) output.icecast(mount = '/radio.mp3', password = 'hackme', %mp3.vbr(), o) - output.icecast(mount = '/radio.opus', password = 'hackme', %opus(bitrate = 64), o) + output.icecast(mount = '/radio.opus', password = 'hackme', %opus(bitrate = 96), o) ''; services.icecast = { enable = true; -- cgit v1.2.3 From 2bb08f9cef428b7e7ac9864eea30a74984aea693 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 6 Jun 2022 12:55:34 +0200 Subject: l radio: add probability of precipitation --- lass/2configs/radio/news.nix | 1 + lass/2configs/radio/weather_for_ips.py | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'lass/2configs/radio') diff --git a/lass/2configs/radio/news.nix b/lass/2configs/radio/news.nix index aa10ea29..99b58511 100644 --- a/lass/2configs/radio/news.nix +++ b/lass/2configs/radio/news.nix @@ -2,6 +2,7 @@ let weather_for_ips = pkgs.writers.writePython3Bin "weather_for_ips" { libraries = [ pkgs.python3Packages.geoip2 ]; + flakeIgnore = [ "E501" ]; } ./weather_for_ips.py; weather_report = pkgs.writers.writeDashBin "weather_report" '' diff --git a/lass/2configs/radio/weather_for_ips.py b/lass/2configs/radio/weather_for_ips.py index 8d9a2e7b..213e69d3 100644 --- a/lass/2configs/radio/weather_for_ips.py +++ b/lass/2configs/radio/weather_for_ips.py @@ -21,13 +21,13 @@ for ip in fileinput.input(): f'&units=metric' ) resp = requests.get(url) - weather = json.loads(resp.text)['current'] + weather = json.loads(resp.text) output.append( - f'Weather report for {location.city.name}' - f', {location.country.name}. ' - f'Currently it is {weather["weather"][0]["description"]} outside ' - f'with a temperature of {weather["temp"]} degrees ' - f'and a windspeed of {weather["wind_speed"]} meter per second. ' + f'Weather report for {location.city.name}, {location.country.name}. ' + f'Currently it is {weather["current"]["weather"][0]["description"]} outside ' + f'with a temperature of {weather["current"]["temp"]} degrees, ' + f'and a windspeed of {weather["current"]["wind_speed"]} meter per second. ' + f'The probability of precipitation is {weather["hourly"][0]["pop"] * 100} percent. ' ) print('\n'.join(output)) -- cgit v1.2.3 From 8974ebb86450941b8db50765f6ee52057eb6d34b Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 6 Jun 2022 16:02:54 +0200 Subject: l radio news: survive newline in input --- lass/2configs/radio/news.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lass/2configs/radio') diff --git a/lass/2configs/radio/news.nix b/lass/2configs/radio/news.nix index 99b58511..d66da813 100644 --- a/lass/2configs/radio/news.nix +++ b/lass/2configs/radio/news.nix @@ -108,8 +108,8 @@ in ;; "POST /") payload=$(head -c "$req_content_length") - echo "$payload" | jq 'has("from") and has("to") and has("text")' >&2 - echo "$payload" | jq -c '{ from: (.from | fromdate | todate), to: (.to | fromdate | todate), text: .text }' >> "$HOME"/news + printf '%s' "$payload" | jq 'has("from") and has("to") and has("text")' >&2 + printf '%s' "$payload" | jq -c '{ from: .from, to: .to, text: .text, priority: (.priority // 0)}' >> "$HOME"/news printf 'HTTP/1.1 200 OK\r\n' printf 'Connection: close\r\n' printf '\r\n' -- cgit v1.2.3 From e0aec32340de2b8b6bedc216ada77c01a980d2b5 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 6 Jun 2022 16:04:10 +0200 Subject: l radio: use radio-news.r for weather report --- lass/2configs/radio/default.nix | 1 + lass/2configs/radio/news.nix | 31 ----------------------- lass/2configs/radio/weather.nix | 55 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 31 deletions(-) create mode 100644 lass/2configs/radio/weather.nix (limited to 'lass/2configs/radio') diff --git a/lass/2configs/radio/default.nix b/lass/2configs/radio/default.nix index 601ef74d..b8d95886 100644 --- a/lass/2configs/radio/default.nix +++ b/lass/2configs/radio/default.nix @@ -107,6 +107,7 @@ let in { imports = [ ./news.nix + ./weather.nix ]; users.users = { diff --git a/lass/2configs/radio/news.nix b/lass/2configs/radio/news.nix index d66da813..c03bd58c 100644 --- a/lass/2configs/radio/news.nix +++ b/lass/2configs/radio/news.nix @@ -1,31 +1,5 @@ { config, lib, pkgs, ... }: let - weather_for_ips = pkgs.writers.writePython3Bin "weather_for_ips" { - libraries = [ pkgs.python3Packages.geoip2 ]; - flakeIgnore = [ "E501" ]; - } ./weather_for_ips.py; - - weather_report = pkgs.writers.writeDashBin "weather_report" '' - set -efu - export PATH="${lib.makeBinPath [ - pkgs.coreutils - pkgs.curl - pkgs.iproute2 - pkgs.jc - pkgs.jq - ]}" - curl -z /tmp/GeoLite2-City.mmdb -o /tmp/GeoLite2-City.mmdb http://c.r/GeoLite2-City.mmdb - MAXMIND_GEOIP_DB="/tmp/GeoLite2-City.mmdb"; export MAXMIND_GEOIP_DB - OPENWEATHER_API_KEY=$(cat "$CREDENTIALS_DIRECTORY/openweather_api"); export OPENWEATHER_API_KEY - ss -no 'sport = :8000' | - jc --ss | jq -r '.[] | - select( - .local_address != "[::ffff:127.0.0.1]" - and .local_address != "[::1]" - ) | .peer_address | gsub("[\\[\\]]"; "") - ' | - ${weather_for_ips}/bin/weather_for_ips - ''; send_to_radio = pkgs.writers.writeDashBin "send_to_radio" '' ${pkgs.vorbis-tools}/bin/oggenc - | @@ -51,7 +25,6 @@ let todays news: $(get_current_news) $(gc_news) - $(weather_report) EOF ''; in @@ -62,7 +35,6 @@ in send_to_radio gc_news get_current_news - weather_report pkgs.curl pkgs.retry ]; @@ -75,9 +47,6 @@ in startAt = "*:00:00"; serviceConfig = { User = "radio-news"; - LoadCredential = [ - "openweather_api:${toString }/openweather_api_key" - ]; }; }; diff --git a/lass/2configs/radio/weather.nix b/lass/2configs/radio/weather.nix new file mode 100644 index 00000000..3beac669 --- /dev/null +++ b/lass/2configs/radio/weather.nix @@ -0,0 +1,55 @@ +{ config, lib, pkgs, ... }: +let + weather_for_ips = pkgs.writers.writePython3Bin "weather_for_ips" { + libraries = [ pkgs.python3Packages.geoip2 ]; + flakeIgnore = [ "E501" ]; + } ./weather_for_ips.py; + + weather_report = pkgs.writers.writeDashBin "weather_report" '' + set -efu + export PATH="${lib.makeBinPath [ + pkgs.coreutils + pkgs.curl + pkgs.iproute2 + pkgs.jc + pkgs.jq + ]}" + curl -z /tmp/GeoLite2-City.mmdb -o /tmp/GeoLite2-City.mmdb http://c.r/GeoLite2-City.mmdb + MAXMIND_GEOIP_DB="/tmp/GeoLite2-City.mmdb"; export MAXMIND_GEOIP_DB + OPENWEATHER_API_KEY=$(cat "$CREDENTIALS_DIRECTORY/openweather_api"); export OPENWEATHER_API_KEY + ss -no 'sport = :8000' | + jc --ss | jq -r '.[] | + select( + .local_address != "[::ffff:127.0.0.1]" + and .local_address != "[::1]" + ) | .peer_address | gsub("[\\[\\]]"; "") + ' | + ${weather_for_ips}/bin/weather_for_ips + ''; +in { + systemd.services.weather = { + path = [ + weather_report + pkgs.retry + pkgs.jq + pkgs.curl + ]; + script = '' + set -xefu + retry -t 5 -d 10 -- weather_report | + jq \ + --arg from "$(date -u +'%FT%TZ')" \ + --arg to "$(date -u +'%FT%TZ' -d '+1 hours')" \ + --slurp --raw-input --compact-output --ascii-output \ + '{text: ., from: $from, to: $to, priority: 100}' | + retry -t 5 -d 10 -- curl -v -d@- http://radio-news.r + ''; + startAt = "*:58:00"; + serviceConfig = { + User = "radio-news"; + LoadCredential = [ + "openweather_api:${toString }/openweather_api_key" + ]; + }; + }; +} -- cgit v1.2.3 From c98ec4f83b6c8ec613d38b97a125850423b9cdd2 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 6 Jun 2022 16:04:37 +0200 Subject: l radio: parse priority, fix timezone --- lass/2configs/radio/news.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lass/2configs/radio') diff --git a/lass/2configs/radio/news.nix b/lass/2configs/radio/news.nix index c03bd58c..e5b5405f 100644 --- a/lass/2configs/radio/news.nix +++ b/lass/2configs/radio/news.nix @@ -8,13 +8,21 @@ let gc_news = pkgs.writers.writeDashBin "gc_news" '' set -xefu + export TZ=UTC #workaround for jq parsing wrong timestamp ${pkgs.coreutils}/bin/cat $HOME/news | ${pkgs.jq}/bin/jq -cs 'map(select((.to|fromdateiso8601) > now)) | .[]' > $HOME/bla-news.tmp ${pkgs.coreutils}/bin/mv $HOME/bla-news.tmp $HOME/news ''; get_current_news = pkgs.writers.writeDashBin "get_current_news" '' set -xefu - ${pkgs.coreutils}/bin/cat $HOME/news | ${pkgs.jq}/bin/jq -rs 'map(select(((.to | fromdateiso8601) > now) and (.from|fromdateiso8601) < now) | .text) | .[]' + export TZ=UTC #workaround for jq parsing wrong timestamp + ${pkgs.coreutils}/bin/cat $HOME/news | ${pkgs.jq}/bin/jq -rs ' + sort_by(.priority) | + map(select( + ((.to | fromdateiso8601) > now) and + (.from|fromdateiso8601) < now) | + .text + ) | .[]' ''; newsshow = pkgs.writers.writeDashBin "newsshow" /* sh */ '' -- cgit v1.2.3 From bdc80e55411e197f89990e988f8b7e67c084d3d3 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 6 Jun 2022 16:04:52 +0200 Subject: l radio weather_for_ips: use better english --- lass/2configs/radio/weather_for_ips.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lass/2configs/radio') diff --git a/lass/2configs/radio/weather_for_ips.py b/lass/2configs/radio/weather_for_ips.py index 213e69d3..f7cc2dac 100644 --- a/lass/2configs/radio/weather_for_ips.py +++ b/lass/2configs/radio/weather_for_ips.py @@ -26,7 +26,7 @@ for ip in fileinput.input(): f'Weather report for {location.city.name}, {location.country.name}. ' f'Currently it is {weather["current"]["weather"][0]["description"]} outside ' f'with a temperature of {weather["current"]["temp"]} degrees, ' - f'and a windspeed of {weather["current"]["wind_speed"]} meter per second. ' + f'and a wind speed of {weather["current"]["wind_speed"]} meters per second. ' f'The probability of precipitation is {weather["hourly"][0]["pop"] * 100} percent. ' ) -- cgit v1.2.3