From 6aa64d77e0f8ef2e42bdb90bc5ed3f6557e3ed81 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 17 Jul 2022 23:10:22 -0500 Subject: Initial commit --- runsfeed | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 runsfeed (limited to 'runsfeed') diff --git a/runsfeed b/runsfeed new file mode 100755 index 0000000..f987a92 --- /dev/null +++ b/runsfeed @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# Run sfeed + +# set -euo pipefail + +main() { + export SFEED_CONFIG="$HOME/.sfeed" + # SFEED_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/sfeed" + export SFEED_DATA="$HOME/.sfeed" + # SFEED_DATA="${XDG_DATA_HOME:-$HOME/.local/share}/sfeed" + export SFEED_OUTPUT="$HOME/.sfeed" + # SFEED_OUTPUT=/var/www/sfeed + export sfeedrc="$SFEED_CONFIG/sfeedrc" + export sfeedpath="$SFEED_DATA/feeds" + test -d "$(dirname "$sfeedrc")" || mkdir -p "$(dirname "$sfeedrc")" + test -d "$sfeedpath" || mkdir -p "$sfeedpath" + + log Updating feeds... + update "$sfeedrc" + log Generating HTML... + html "$sfeedpath"/* >"$SFEED_OUTPUT/index.html" + log + LIMIT=0 html "$sfeedpath"/* >"$SFEED_OUTPUT/feeds.html" + log + log Generating RSS... + atom "$sfeedpath" >"$SFEED_OUTPUT/feeds.xml" + atom "$sfeedpath" 7 >"$SFEED_OUTPUT/feeds-short.xml" + log Generating OPML... + opml "$sfeedrc" >"$SFEED_OUTPUT/feeds.opml" + log Done. +} + +log() { + printf '%s\n' "$*" >&2 +} + +update() { + cmd="$(command -v sfeed_update_xargs || echo ./sfeed_update_xargs)" + "$cmd" "$@" +} + +opml() { + sfeed_opml_export "$@" +} + +html() { + converter="$(command -v sfeed_html.sh || echo ./sfeed_html.sh)" + "$converter" "$@" +} + +atom() ( # atom DIRECTORY [DAYS] + curd="$PWD" + cd "$1" || return 1 + if [ $# -eq 2 ]; then + old=$(($(date +%s) - ($2 * 24 * 3600))) + else + old=0 + fi + awk -F $'\t' -v old="$old" \ + 'BEGIN{OFS="\t"} int($1)>=old{$2="["FILENAME"] "$2;print}' \ + * | + sort -k1,1rn | + sfeed_atom +) + +sfeed_archive() ( # sfeed_archive FEED ... + for feed; do + awk -v old="$(($(date +%s) - (15 * 24 * 3600)))" \ + -F '\t' 'int($1) > old' <"$feed" >"$feed.new" + mv "$feed" "$feed.old" + mv "$feed.new" "$feed" + done +) + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + main "$@" +fi -- cgit 1.4.1-21-gabe81