Compare commits

...

9 Commits

Author SHA1 Message Date
856160cc5f feat: remove news and programmation sections
All checks were successful
kipp-news/pipeline/head This commit looks good
2025-06-15 23:25:06 +02:00
fae8990599 chore: add FORCE_SEND parameter in Jenkins pipeline
All checks were successful
kipp-news/pipeline/head This commit looks good
2025-04-14 09:09:35 +02:00
8ba11bfccc fix: news api call
All checks were successful
kipp-news/pipeline/head This commit looks good
2025-03-24 09:19:48 +01:00
f30dfd02dd feat: prevent reddit rss endpoint blacklisting
All checks were successful
kipp-news/pipeline/head This commit looks good
2025-03-24 09:13:21 +01:00
2fe16ffa2f ci: do not send message on global channel on manual triggering
All checks were successful
kipp-news/pipeline/head This commit looks good
2025-02-02 19:43:15 +01:00
248cfede9e fix: news api url
All checks were successful
kipp-news/pipeline/head This commit looks good
2025-02-02 19:38:27 +01:00
fd4dbec9c9 ci: add missing coreutils
All checks were successful
kipp-news/pipeline/head This commit looks good
2025-02-02 19:30:45 +01:00
1dbee20c42 ci: inject NEWS_API_KEY credentials
All checks were successful
kipp-news/pipeline/head This commit looks good
2025-02-02 19:24:33 +01:00
631c559d59 feat: integrate news api 2025-02-02 19:21:56 +01:00
3 changed files with 79 additions and 21 deletions

38
Jenkinsfile vendored
View File

@ -13,23 +13,29 @@ pipeline {
cron('0 9 * * 1')
}
parameters {
booleanParam(name: 'FORCE_SEND', defaultValue: false, description: 'Force send of newsletter')
}
stages {
stage("Send newsletter") {
when {
anyOf {
triggeredBy cause: "UserIdCause", detail: "wpetit"
triggeredBy 'TimerTrigger'
expression { params.FORCE_SEND == true }
}
}
steps {
script {
String newsletter = sh(script: "bash ./generate-newsletter.sh", returnStdout: true)
if (newsletter) {
rocketSend(
channel: '#TechWatch',
message: newsletter,
rawMessage: true
)
withCredentials([string(credentialsId: 'NEWS_API_KEY', variable: 'NEWS_API_KEY')]) {
String newsletter = sh(script: "bash ./generate-newsletter.sh", returnStdout: true)
if (newsletter) {
rocketSend(
channel: '#TechWatch',
message: newsletter,
rawMessage: true
)
}
}
}
}
@ -40,13 +46,15 @@ pipeline {
}
steps {
script {
String newsletter = sh(script: "bash ./generate-newsletter.sh", returnStdout: true)
if (newsletter) {
rocketSend(
channel: '@wpetit',
message: newsletter,
rawMessage: true
)
withCredentials([string(credentialsId: 'NEWS_API_KEY', variable: 'NEWS_API_KEY')]) {
String newsletter = sh(script: "bash ./generate-newsletter.sh", returnStdout: true)
if (newsletter) {
rocketSend(
channel: '@wpetit',
message: newsletter,
rawMessage: true
)
}
}
}
}

View File

@ -4,6 +4,25 @@ set -eo pipefail
NEWSLETTER=""
function scrape {
curl \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
-H 'accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7' \
-H 'cache-control: no-cache' \
-H 'pragma: no-cache' \
-H 'priority: u=0, i' \
-H 'sec-ch-ua: "Not:A-Brand";v="24", "Chromium";v="134"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
-H 'sec-fetch-dest: document' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-user: ?1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36' \
$@
}
function write {
local content=$@
NEWSLETTER="${NEWSLETTER}${content}"
@ -28,7 +47,7 @@ function include_subreddit_top_of_the_week {
local title=$1
local subreddit=$2
local total=$3
local top_of_the_week=$(curl -sk --retry 5 "https://www.reddit.com/r/$subreddit/top/.rss?sort=top&t=week" | npx xml2json | jq --arg TOTAL "$total" '.feed.entry[0:($TOTAL|tonumber)]')
local top_of_the_week=$(scrape -sk --retry 5 "https://www.reddit.com/r/$subreddit/top/.rss?sort=top&t=week" | npx xml2json | jq --arg TOTAL "$total" '.feed.entry[0:($TOTAL|tonumber)]')
if [ -z "$top_of_the_week" ]; then
return
@ -54,7 +73,7 @@ function include_subreddit_top_of_the_week {
function include_linuxfr_latest {
local total=5
local linuxfr_latest=$(curl -sk --retry 5 https://linuxfr.org/news.atom | npx xml2json | jq --arg TOTAL "$total" '.feed.entry[0:($TOTAL|tonumber)]')
local linuxfr_latest=$(scrape -sk --retry 5 https://linuxfr.org/news.atom | npx xml2json | jq --arg TOTAL "$total" '.feed.entry[0:($TOTAL|tonumber)]')
if [ -z "$linuxfr_latest" ]; then
return
@ -79,7 +98,7 @@ function include_linuxfr_latest {
}
function include_hackernews_top5 {
local hackernews_top5=$(curl -sk --retry 5 https://hacker-news.firebaseio.com/v0/topstories.json | jq -r '.[0:5] | .[]')
local hackernews_top5=$(scrape -sk --retry 5 https://hacker-news.firebaseio.com/v0/topstories.json | jq -r '.[0:5] | .[]')
if [ -z "$hackernews_top5" ]; then
return
@ -89,7 +108,7 @@ function include_hackernews_top5 {
writeln "#### Hackernews"
for story_id in ${hackernews_top5}; do
local hackernews_story=$(curl -sk --retry 5 https://hacker-news.firebaseio.com/v0/item/$story_id.json?print=pretty)
local hackernews_story=$(scrape -sk --retry 5 https://hacker-news.firebaseio.com/v0/item/$story_id.json?print=pretty)
local story_title=$(echo $hackernews_story | jq -r '.title')
local story_url=$(echo $hackernews_story | jq -r '.url')
local story_author=$(echo $hackernews_story | jq -r '.by')
@ -103,8 +122,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=$(scrape -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

View File

@ -1,6 +1,6 @@
FROM alpine:3.21
RUN apk add nodejs npm jq bash curl ca-certificates python3 build-base
RUN apk add nodejs npm jq bash curl ca-certificates python3 build-base coreutils
RUN npm install -g xml2json