2025-12-27 22:22:54 +01:00
|
|
|
{
|
|
|
|
|
writers,
|
|
|
|
|
lib,
|
|
|
|
|
gnused,
|
|
|
|
|
curl,
|
|
|
|
|
jq,
|
|
|
|
|
yq,
|
|
|
|
|
}:
|
2026-02-15 16:43:04 +01:00
|
|
|
let
|
|
|
|
|
model = "gemini-2.5-flash-lite";
|
|
|
|
|
in
|
2025-06-03 20:07:49 +02:00
|
|
|
writers.writeBashBin "radio-news" ''
|
|
|
|
|
set -efu
|
2025-12-27 22:22:54 +01:00
|
|
|
PATH=$PATH:${
|
|
|
|
|
lib.makeBinPath [
|
|
|
|
|
gnused
|
|
|
|
|
curl
|
|
|
|
|
jq
|
|
|
|
|
yq
|
|
|
|
|
]
|
|
|
|
|
}
|
2025-06-03 20:07:49 +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})
|
|
|
|
|
'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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 as possible, and easy to follow.
|
|
|
|
|
Please no unnecessary explanations why the news is good.
|
|
|
|
|
|
|
|
|
|
Begin the digest with: "Here's your good news update."
|
|
|
|
|
EOF
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
REQUEST=$(cat <<EOF
|
|
|
|
|
{
|
|
|
|
|
"system_instruction": {
|
|
|
|
|
"parts": [
|
|
|
|
|
{
|
|
|
|
|
"text": $(jq -Rs <<< "$SYSTEM_PROMPT")
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"contents": [
|
|
|
|
|
{
|
|
|
|
|
"parts": [
|
|
|
|
|
{
|
|
|
|
|
"text": $(jq -Rs <<< "$EVENTS")
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
EOF
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-15 16:43:04 +01:00
|
|
|
echo "$REQUEST" | curl "https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=$GEMINI_API_KEY" -s -H "Content-Type: application/json" -d @-
|
2025-06-03 20:07:49 +02:00
|
|
|
''
|