diff options
author | lassulus <lassulus@lassul.us> | 2022-06-06 16:04:10 +0200 |
---|---|---|
committer | lassulus <lassulus@lassul.us> | 2022-06-06 16:04:10 +0200 |
commit | e0aec32340de2b8b6bedc216ada77c01a980d2b5 (patch) | |
tree | cf1ad236f2262cef77435767c39f5330fe509136 /lass/2configs | |
parent | 8974ebb86450941b8db50765f6ee52057eb6d34b (diff) |
l radio: use radio-news.r for weather report
Diffstat (limited to 'lass/2configs')
-rw-r--r-- | lass/2configs/radio/default.nix | 1 | ||||
-rw-r--r-- | lass/2configs/radio/news.nix | 31 | ||||
-rw-r--r-- | lass/2configs/radio/weather.nix | 55 |
3 files changed, 56 insertions, 31 deletions
diff --git a/lass/2configs/radio/default.nix b/lass/2configs/radio/default.nix index 601ef74dd..b8d958865 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 d66da813f..c03bd58c7 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 <secrets>}/openweather_api_key" - ]; }; }; diff --git a/lass/2configs/radio/weather.nix b/lass/2configs/radio/weather.nix new file mode 100644 index 000000000..3beac6693 --- /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 <secrets>}/openweather_api_key" + ]; + }; + }; +} |