feat: integrate news api

This commit is contained in:
wpetit 2025-02-02 19:21:56 +01:00
parent c58a343679
commit 631c559d59

View File

@ -103,8 +103,39 @@ function include_hackernews_top5 {
done 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() { 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 "Go" "golang" 5
include_subreddit_top_of_the_week "Kubernetes" "kubernetes" 5 include_subreddit_top_of_the_week "Kubernetes" "kubernetes" 5
include_subreddit_top_of_the_week "Python" "python" 5 include_subreddit_top_of_the_week "Python" "python" 5