1
0
mirror of https://github.com/kmein/niveum synced 2026-03-22 21:01:07 +01:00
Files
niveum/systems/makanek/radio-news.nix

88 lines
2.6 KiB
Nix
Raw Normal View History

2022-03-10 21:52:12 +01:00
{
2025-05-13 19:51:43 +02:00
config,
2022-03-10 21:52:12 +01:00
pkgs,
lib,
...
}: let
inherit (import ../../lib) serveHtml;
remote = "https://cgit.lassul.us/stockholm";
2022-03-10 21:52:12 +01:00
in {
services.nginx.virtualHosts."redaktion.r".locations."/".extraConfig = serveHtml ../../lib/radio-news.html pkgs;
2025-05-13 19:51:43 +02:00
age.secrets = {
gemini-api-key.file = ../../secrets/gemini-api-key.age;
};
systemd.services.news-digest = {
enable = true;
wantedBy = ["multi-user.target"];
wants = ["network-online.target"];
serviceConfig.LoadCredential = [
"gemini-api-key:${config.age.secrets.gemini-api-key.path}"
];
2025-05-16 14:03:42 +02:00
startAt = "*:50";
2025-05-13 19:51:43 +02:00
script = ''
2025-05-13 20:22:42 +02:00
set -efu
2025-05-28 09:32:26 +02:00
PATH=$PATH:${lib.makeBinPath [pkgs.w3m pkgs.gnused pkgs.curl pkgs.jq pkgs.yq]}
2025-05-13 19:51:43 +02:00
2025-05-13 20:22:42 +02:00
export GEMINI_API_KEY="$(cat "$CREDENTIALS_DIRECTORY/gemini-api-key")"
2025-05-13 19:51:43 +02:00
2025-05-28 09:32:26 +02:00
EVENTS=$(
curl https://www.goodnewsnetwork.org/feed/ \
| xq '
.rss.channel.item
| map(select((.pubDate|strptime("%a, %d %b %Y %H:%M:%S %z")) as $date | ($date | mktime) > (now - (60 * 60 * 24))) | {title, description})
'
)
2025-05-13 19:51:43 +02:00
SYSTEM_PROMPT=$(cat <<EOF
You are a news anchor writing a short news digest for a radio broadcast.
Summarize the following news headlines into a cohesive, engaging script under 400 words.
Keep it professional, concise, and easy to follow.
2025-05-28 09:32:26 +02:00
Begin the digest with: "Here's your good news update for $(date -u +"%B %d, %Y")."
2025-05-13 19:51:43 +02:00
EOF
)
REQUEST=$(cat <<EOF
{
"system_instruction": {
"parts": [
{
"text": $(jq -Rs <<< "$SYSTEM_PROMPT")
}
]
},
"contents": [
{
"parts": [
{
2025-05-28 09:32:26 +02:00
"text": $(jq -Rs <<< "$EVENTS")
2025-05-13 19:51:43 +02:00
}
]
}
]
}
EOF
)
RESPONSE=$(echo "$REQUEST" | curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-8b:generateContent?key=$GEMINI_API_KEY" -s -H "Content-Type: application/json" -d @-)
2025-05-16 10:08:30 +02:00
echo "$RESPONSE" | jq --arg from "$(date -u -Is | sed 's/+00:00/Z/')" --arg to "$(date -u -Is -d 'now + 30 minutes' | sed 's/+00:00/Z/')" '
2025-05-13 19:51:43 +02:00
{
from: $from,
to: $to,
text: .candidates[].content.parts[].text
}' | curl -s -X POST http://radio-news.r -H "Content-Type: application/json" -d @-
'';
};
2022-05-22 11:47:59 +02:00
niveum.passport.services = [
{
title = "Retiolum Radio News";
link = "http://redaktion.r";
description = "supplies git history news to radio lassulus and lets you enter your own.";
}
];
2022-02-22 20:34:53 +01:00
}