127 lines
3.6 KiB
Bash
Executable File
127 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eo pipefail
|
|
|
|
NEWSLETTER=""
|
|
|
|
function write {
|
|
local content=$@
|
|
NEWSLETTER="${NEWSLETTER}${content}"
|
|
}
|
|
|
|
function writeln {
|
|
write "$@\n"
|
|
}
|
|
|
|
function include_illustration_of_the_week {
|
|
local illustration_of_the_week=$(date +"illustrations/%Y/small/%U.jpg")
|
|
|
|
if [ ! -f "${illustration_of_the_week}" ]; then
|
|
return
|
|
fi
|
|
|
|
writeln
|
|
writeln "![L'illustration de la semaine](https://forge.cadoles.com/wpetit/cazette/raw/branch/master/$illustration_of_the_week)"
|
|
}
|
|
|
|
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)]')
|
|
|
|
if [ -z "$top_of_the_week" ]; then
|
|
return
|
|
fi
|
|
|
|
writeln
|
|
writeln "#### ${title}"
|
|
|
|
for index in $(seq 0 $(( $total - 1 ))); do
|
|
local entry=$(echo $top_of_the_week | jq --arg INDEX $index '.[$INDEX | tonumber]')
|
|
local entry_title=$(echo $entry | jq -r '.title')
|
|
local entry_url=$(echo $entry | jq -r '.link.href')
|
|
local entry_author=$(echo $entry | jq -r '.author? | .name?')
|
|
|
|
write "- [${entry_title}]($entry_url)"
|
|
if [ ! -z "${entry_author}" ]; then
|
|
writeln " par _ ${entry_author} _"
|
|
else
|
|
writeln
|
|
fi
|
|
done
|
|
}
|
|
|
|
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)]')
|
|
|
|
if [ -z "$linuxfr_latest" ]; then
|
|
return
|
|
fi
|
|
|
|
writeln
|
|
writeln "#### LinuxFr.org"
|
|
|
|
for index in $(seq 0 $(( $total - 1 ))); do
|
|
local entry=$(echo $linuxfr_latest | jq --arg INDEX $index '.[$INDEX | tonumber]')
|
|
local entry_title=$(echo $entry | jq -r '.title')
|
|
local entry_url=$(echo $entry | jq -r '.link.href')
|
|
local entry_author=$(echo $entry | jq -r '[.author? | .[] | .name?] | join(", ")')
|
|
|
|
write "- [${entry_title}]($entry_url)"
|
|
if [ ! -z "${entry_author}" ]; then
|
|
writeln " par _ ${entry_author} _"
|
|
else
|
|
writeln
|
|
fi
|
|
done
|
|
}
|
|
|
|
function include_hackernews_top5 {
|
|
local hackernews_top5=$(curl -sk --retry 5 https://hacker-news.firebaseio.com/v0/topstories.json | jq -r '.[0:5] | .[]')
|
|
|
|
if [ -z "$hackernews_top5" ]; then
|
|
return
|
|
fi
|
|
|
|
writeln
|
|
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 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')
|
|
|
|
write "- [${story_title}](${story_url})"
|
|
if [ ! -z "${story_author}" ]; then
|
|
writeln " par _ ${story_author} _"
|
|
else
|
|
writeln
|
|
fi
|
|
done
|
|
}
|
|
|
|
function main() {
|
|
include_subreddit_top_of_the_week "Généralités" "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
|
|
include_subreddit_top_of_the_week "Symfony" "symfony" 5
|
|
include_subreddit_top_of_the_week "PHP" "php" 5
|
|
include_linuxfr_latest
|
|
include_hackernews_top5
|
|
include_illustration_of_the_week
|
|
|
|
if [ ! -z "$NEWSLETTER" ]; then
|
|
echo "### La Cazette N°$(date +%Y-%U)"
|
|
echo "_Chaque semaine, une sélection de nouvelles et d'articles de la communauté du développement logiciel._"
|
|
echo -e $NEWSLETTER
|
|
echo "**Bonne semaine à tous ! :robot:**"
|
|
echo
|
|
echo "_Generated by [cazette](https://forge.cadoles.com/wpetit/cazette)_"
|
|
fi
|
|
}
|
|
|
|
main |