summaryrefslogtreecommitdiffstats
path: root/lass
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2022-03-06 10:43:33 +0100
committertv <tv@krebsco.de>2022-03-06 10:43:33 +0100
commit5182daaaf4cadaba84331a34b5455bf9dff131b6 (patch)
treedeaa480a8ad3a9aaad6176bc14804f2bb6569c30 /lass
parent6bcbb9adae290249988c86da35b2b5236df6ce96 (diff)
parent87a44dd1573cbdc8f0fc3553b0896b470bcfa44d (diff)
Merge remote-tracking branch 'prism/master'
Diffstat (limited to 'lass')
-rw-r--r--lass/2configs/bitcoin.nix9
-rw-r--r--lass/2configs/radio-news.nix53
2 files changed, 50 insertions, 12 deletions
diff --git a/lass/2configs/bitcoin.nix b/lass/2configs/bitcoin.nix
index 9aa97a8ce..de6562cbc 100644
--- a/lass/2configs/bitcoin.nix
+++ b/lass/2configs/bitcoin.nix
@@ -5,15 +5,6 @@ let
in {
users.extraUsers = {
- bch = {
- name = "bch";
- description = "user for bch stuff";
- home = "/home/bch";
- useDefaultShell = true;
- createHome = true;
- packages = [ pkgs.electron-cash ];
- isNormalUser = true;
- };
bitcoin = {
name = "bitcoin";
description = "user for bitcoin stuff";
diff --git a/lass/2configs/radio-news.nix b/lass/2configs/radio-news.nix
index a4e28c1b1..eb7d3bd9a 100644
--- a/lass/2configs/radio-news.nix
+++ b/lass/2configs/radio-news.nix
@@ -1,8 +1,8 @@
-{ config, pkgs, ... }: with pkgs.stockholm.lib;
+{ config, lib, pkgs, ... }:
let
weather_report = pkgs.writers.writeDashBin "weather_report" ''
set -efu
- ${pkgs.curl}/bin/curl -sSL https://wttr.in/''${1-}?format=j1 \
+ ${pkgs.curl}/bin/curl -fsSL https://wttr.in/''${1-}?format=j1 \
| ${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."]
@@ -14,11 +14,25 @@ let
${pkgs.libshout}/bin/shout --format ogg --host localhost --port 1338 --mount /live
'';
+ 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) | .[]'
+ '';
+
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.
+ todays news:
+ $(get_current_news)
+ $(gc_news)
$(weather_report berlin)
$(weather_report 70173)
$(weather_report munich)
@@ -30,6 +44,8 @@ in
path = [
newsshow
send_to_radio
+ gc_news
+ get_current_news
weather_report
pkgs.curl
pkgs.retry
@@ -37,10 +53,41 @@ in
script = ''
set -efu
retry -t 5 -d 10 -- newsshow |
- retry -t 5 -d 10 -- curl -SsG http://tts.r/api/tts --data-urlencode 'text@-' |
+ retry -t 5 -d 10 -- curl -fSsG http://tts.r/api/tts --data-urlencode 'text@-' |
retry -t 5 -d 10 -- send_to_radio
'';
startAt = "*: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
+ ''}'';
};
## debug