2022-02-19 23:19:23 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2022-02-07 16:32:13 +00:00
|
|
|
let
|
|
|
|
weather_report = pkgs.writers.writeDashBin "weather_report" ''
|
|
|
|
set -efu
|
2022-02-19 23:19:23 +00:00
|
|
|
${pkgs.curl}/bin/curl -fsSL https://wttr.in/''${1-}?format=j1 \
|
2022-02-07 16:32:13 +00:00
|
|
|
| ${pkgs.jq}/bin/jq -r '
|
|
|
|
[.nearest_area[0] | "Weather report for \(.areaName[0].value), \(.country[0].value)."]
|
|
|
|
+ [.current_condition[0] | "Currently it is \(.weatherDesc[0].value) outside with a temperature of \(.temp_C) degrees."]
|
|
|
|
| join("\n")
|
|
|
|
'
|
|
|
|
'';
|
|
|
|
send_to_radio = pkgs.writers.writeDashBin "send_to_radio" ''
|
|
|
|
${pkgs.vorbisTools}/bin/oggenc - |
|
|
|
|
${pkgs.libshout}/bin/shout --format ogg --host localhost --port 1338 --mount /live
|
|
|
|
'';
|
|
|
|
|
2022-02-19 23:19:23 +00:00
|
|
|
gc_news = pkgs.writers.writeDashBin "gc_news" ''
|
|
|
|
set -xefu
|
|
|
|
${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) | .[]'
|
|
|
|
'';
|
|
|
|
|
2022-02-07 16:32:13 +00:00
|
|
|
newsshow = pkgs.writers.writeDashBin "newsshow" /* sh */ ''
|
|
|
|
echo "
|
|
|
|
hello crabpeople!
|
|
|
|
$(${pkgs.ddate}/bin/ddate | sed 's/YOLD/Year of Discord/')!
|
|
|
|
It is $(date --utc +%H) o clock UTC.
|
2022-02-19 23:19:23 +00:00
|
|
|
todays news:
|
|
|
|
$(get_current_news)
|
|
|
|
$(gc_news)
|
2022-02-07 16:32:13 +00:00
|
|
|
$(weather_report berlin)
|
2022-02-08 17:04:18 +00:00
|
|
|
$(weather_report 70173)
|
2022-02-07 16:32:13 +00:00
|
|
|
$(weather_report munich)
|
|
|
|
"
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
systemd.services.newsshow = {
|
|
|
|
path = [
|
|
|
|
newsshow
|
|
|
|
send_to_radio
|
2022-02-19 23:19:23 +00:00
|
|
|
gc_news
|
|
|
|
get_current_news
|
2022-02-07 16:32:13 +00:00
|
|
|
weather_report
|
|
|
|
pkgs.curl
|
2022-02-08 17:03:58 +00:00
|
|
|
pkgs.retry
|
2022-02-07 16:32:13 +00:00
|
|
|
];
|
|
|
|
script = ''
|
|
|
|
set -efu
|
2022-02-08 17:03:58 +00:00
|
|
|
retry -t 5 -d 10 -- newsshow |
|
2022-02-19 23:19:23 +00:00
|
|
|
retry -t 5 -d 10 -- curl -fSsG http://tts.r/api/tts --data-urlencode 'text@-' |
|
2022-02-08 17:03:58 +00:00
|
|
|
retry -t 5 -d 10 -- send_to_radio
|
2022-02-07 16:32:13 +00:00
|
|
|
'';
|
|
|
|
startAt = "*:00:00";
|
2022-02-19 23:19:23 +00:00
|
|
|
serviceConfig = {
|
|
|
|
User = "radio-news";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
krebs.iptables.tables.filter.INPUT.rules = [
|
|
|
|
{ predicate = "-p tcp --dport 7999"; target = "ACCEPT"; }
|
|
|
|
];
|
|
|
|
|
|
|
|
krebs.htgen.news = {
|
|
|
|
port = 7999;
|
|
|
|
user = {
|
|
|
|
name = "radio-news";
|
|
|
|
};
|
|
|
|
script = ''. ${pkgs.writers.writeDash "htgen-news" ''
|
|
|
|
set -xefu
|
|
|
|
case "$Method $Request_URI" in
|
|
|
|
"POST /")
|
|
|
|
payload=$(head -c "$req_content_length" \
|
|
|
|
| sed 's/+/ /g;s/%\(..\)/\\x\1/g;' \
|
|
|
|
| xargs -0 echo -e \
|
|
|
|
)
|
|
|
|
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 'HTTP/1.1 200 OK\r\n'
|
|
|
|
printf 'Connection: close\r\n'
|
|
|
|
printf '\r\n'
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
''}'';
|
2022-02-07 16:32:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
## debug
|
|
|
|
# environment.systemPackages = [
|
|
|
|
# weather_report
|
|
|
|
# send_to_radio
|
|
|
|
# newsshow
|
|
|
|
# ];
|
|
|
|
}
|