summaryrefslogtreecommitdiffstats
path: root/lass/2configs/radio/news.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2022-06-07 00:17:23 +0200
committermakefu <github@syntax-fehler.de>2022-06-07 00:17:23 +0200
commit9c1799914a2e6f2dc736fe2eaad7134602a3d837 (patch)
tree08347f7f29bc00c3b40be2a49e069268c0163716 /lass/2configs/radio/news.nix
parent1e405be047a79e1abd0c28e52b5009b9675909b8 (diff)
parentbdc80e55411e197f89990e988f8b7e67c084d3d3 (diff)
Merge remote-tracking branch 'lass/master' into 22.05
Diffstat (limited to 'lass/2configs/radio/news.nix')
-rw-r--r--lass/2configs/radio/news.nix46
1 files changed, 12 insertions, 34 deletions
diff --git a/lass/2configs/radio/news.nix b/lass/2configs/radio/news.nix
index 27b124093..e5b5405ff 100644
--- a/lass/2configs/radio/news.nix
+++ b/lass/2configs/radio/news.nix
@@ -1,45 +1,28 @@
{ config, lib, pkgs, ... }:
let
- weather_for_ips = pkgs.writers.writePython3Bin "weather_for_ips" {
- libraries = [ pkgs.python3Packages.geoip2 ];
- } ./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.vorbisTools}/bin/oggenc - |
+ ${pkgs.vorbis-tools}/bin/oggenc - |
${pkgs.libshout}/bin/shout --format ogg --host localhost --port 1338 --mount /live
'';
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 */ ''
@@ -50,7 +33,6 @@ let
todays news:
$(get_current_news)
$(gc_news)
- $(weather_report)
EOF
'';
in
@@ -61,7 +43,6 @@ in
send_to_radio
gc_news
get_current_news
- weather_report
pkgs.curl
pkgs.retry
];
@@ -74,9 +55,6 @@ in
startAt = "*:00:00";
serviceConfig = {
User = "radio-news";
- LoadCredential = [
- "openweather_api:${toString <secrets>}/openweather_api_key"
- ];
};
};
@@ -107,8 +85,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'