From 631c559d5984e779a4bfc8b3cc0c84a6e7b2d354 Mon Sep 17 00:00:00 2001 From: William Petit Date: Sun, 2 Feb 2025 19:21:56 +0100 Subject: [PATCH] feat: integrate news api --- generate-newsletter.sh | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/generate-newsletter.sh b/generate-newsletter.sh index 3e759a6..7c2d1ae 100755 --- a/generate-newsletter.sh +++ b/generate-newsletter.sh @@ -103,8 +103,39 @@ function include_hackernews_top5 { done } +function include_news_api_latest_week { + if [ -z "${NEWS_API_KEY}" ]; then + return + fi + + local title=$1 + local query=$2 + local total=$3 + local since=$(date -d '- 7 days' +%Y-%m-%d) + local news_of_the_week=$(curl -sk --retry 5 -H "X-Api-Key: ${NEWS_API_KEY}" -H 'User-Agent: Cazette/1.0' "https://api.newsdatahub.com/v1/news?language=fr&topic=technology&topic=business&topic=politics&topic=education&topic=innovation&topic=internet&&q=${query}&start_date=${since}" | jq '.data') + + if [ -z "$news_of_the_week" ]; then + return + fi + + writeln + writeln "#### $title" + + for index in $(seq 0 $(( $total - 1 ))); do + local entry=$(echo $news_of_the_week | jq --arg INDEX $index '.[$INDEX | tonumber]') + local entry_title=$(echo $entry | jq -r '.title') + local entry_url=$(echo $entry | jq -r '.article_link') + + write "- [${entry_title}]($entry_url)" + writeln + done + + +} + function main() { - include_subreddit_top_of_the_week "Généralités" "programmation" 5 + include_news_api_latest_week "Actualités" '%22open%20source%22%20OR%20%22logiciel%20libre%22' 5 + include_subreddit_top_of_the_week "Programmation" "programmation" 5 include_subreddit_top_of_the_week "Go" "golang" 5 include_subreddit_top_of_the_week "Kubernetes" "kubernetes" 5 include_subreddit_top_of_the_week "Python" "python" 5