From 3215f81f46aca11000560d3a8fcacb349d2e75f3 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 27 Sep 2023 03:07:27 -0700 Subject: feat(suzuri): rss generator --- README.md | 5 ++++- suzuri | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b7f5b6d..adb5fab 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Obtain your sumi.news token via the `s` cookie on sumi.news. ### `--help` ```text -usage: sumi token [folder] +usage: suzuri token [folder] positional arguments: token sumi.news session token @@ -34,6 +34,7 @@ environment variables: SUZURI_REVERSE reverse the output feed SUZURI_MINIMAL output only linked titles SUZURI_RAW output raw markdown + SUZURI_RSS output raw application/rss+xml ``` Optionally, omit the token and folder arguments and export the environment @@ -51,6 +52,8 @@ variables `SUZURI_TOKEN` and `SUZURI_FOLDER`. - Pipe it into [`gum`'s](https://github.com/charmbracelet/gum) `choose` subcommand - Display the most recent feed item in your status-bar - Echo out the most recent feed item when you start your shell +- Generate an RSS feed of your feeds to read with local tooling; e.g., + [newsboat](https://newsboat.org/). ## Licence diff --git a/suzuri b/suzuri index d1c5f94..a14670b 100755 --- a/suzuri +++ b/suzuri @@ -18,6 +18,7 @@ environment variables: SUZURI_REVERSE reverse the output feed SUZURI_MINIMAL output only linked titles SUZURI_RAW output raw markdown + SUZURI_RSS output raw application/rss+xml EOF exit @@ -46,6 +47,45 @@ if [[ -n "${SUZURI_MINIMAL}" ]]; then body="$(echo "${body}" | grep -oP '^## \K.*' | sed "s/##//" || true)" fi +if [[ -n "${SUZURI_RSS}" ]]; then + IFS=$'\n' read -r -d '' -a items <<<"${body}" + + cat < + + sumi.news + https://sumi.news + Read the entire Internet at once – all the news, RSS, and newsletters on one page. + suzuri + en-US + $(date +'%a, %d %b %Y %H:%M:%S %z') + $(date +'%a, %d %b %Y %H:%M:%S %z') +EOF + + for item in "${items[@]}"; do + if [[ ${item} =~ ^\[(.+)\] ]]; then + title="${BASH_REMATCH[1]}" + fi + + regex="\((http[^)]+)\)" + if [[ ${item} =~ ${regex} ]]; then + url="${BASH_REMATCH[1]}" + fi + + cat < + ${title} + ${url} + $(date -d "today" '+%a, %d %b %Y 00:00:00 %z') + +EOF + done + + echo "" + + exit +fi + if [[ -n "${SUZURI_RAW}" ]]; then echo "${body}" else -- cgit v1.2.3