about summary refs log tree commit diff stats
path: root/runsfeed
diff options
context:
space:
mode:
authorCase Duckworth2022-07-17 23:10:22 -0500
committerCase Duckworth2022-07-17 23:10:22 -0500
commit6aa64d77e0f8ef2e42bdb90bc5ed3f6557e3ed81 (patch)
treed54f6332408be6add8865714cb2bf1ef54160bdf /runsfeed
downloadsfeed-6aa64d77e0f8ef2e42bdb90bc5ed3f6557e3ed81.tar.gz
sfeed-6aa64d77e0f8ef2e42bdb90bc5ed3f6557e3ed81.zip
Initial commit
Diffstat (limited to 'runsfeed')
-rwxr-xr-xrunsfeed77
1 files changed, 77 insertions, 0 deletions
diff --git a/runsfeed b/runsfeed new file mode 100755 index 0000000..f987a92 --- /dev/null +++ b/runsfeed
@@ -0,0 +1,77 @@
1#!/usr/bin/env bash
2# Run sfeed
3
4# set -euo pipefail
5
6main() {
7 export SFEED_CONFIG="$HOME/.sfeed"
8 # SFEED_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/sfeed"
9 export SFEED_DATA="$HOME/.sfeed"
10 # SFEED_DATA="${XDG_DATA_HOME:-$HOME/.local/share}/sfeed"
11 export SFEED_OUTPUT="$HOME/.sfeed"
12 # SFEED_OUTPUT=/var/www/sfeed
13 export sfeedrc="$SFEED_CONFIG/sfeedrc"
14 export sfeedpath="$SFEED_DATA/feeds"
15 test -d "$(dirname "$sfeedrc")" || mkdir -p "$(dirname "$sfeedrc")"
16 test -d "$sfeedpath" || mkdir -p "$sfeedpath"
17
18 log Updating feeds...
19 update "$sfeedrc"
20 log Generating HTML...
21 html "$sfeedpath"/* >"$SFEED_OUTPUT/index.html"
22 log
23 LIMIT=0 html "$sfeedpath"/* >"$SFEED_OUTPUT/feeds.html"
24 log
25 log Generating RSS...
26 atom "$sfeedpath" >"$SFEED_OUTPUT/feeds.xml"
27 atom "$sfeedpath" 7 >"$SFEED_OUTPUT/feeds-short.xml"
28 log Generating OPML...
29 opml "$sfeedrc" >"$SFEED_OUTPUT/feeds.opml"
30 log Done.
31}
32
33log() {
34 printf '%s\n' "$*" >&2
35}
36
37update() {
38 cmd="$(command -v sfeed_update_xargs || echo ./sfeed_update_xargs)"
39 "$cmd" "$@"
40}
41
42opml() {
43 sfeed_opml_export "$@"
44}
45
46html() {
47 converter="$(command -v sfeed_html.sh || echo ./sfeed_html.sh)"
48 "$converter" "$@"
49}
50
51atom() ( # atom DIRECTORY [DAYS]
52 curd="$PWD"
53 cd "$1" || return 1
54 if [ $# -eq 2 ]; then
55 old=$(($(date +%s) - ($2 * 24 * 3600)))
56 else
57 old=0
58 fi
59 awk -F $'\t' -v old="$old" \
60 'BEGIN{OFS="\t"} int($1)>=old{$2="["FILENAME"] "$2;print}' \
61 * |
62 sort -k1,1rn |
63 sfeed_atom
64)
65
66sfeed_archive() ( # sfeed_archive FEED ...
67 for feed; do
68 awk -v old="$(($(date +%s) - (15 * 24 * 3600)))" \
69 -F '\t' 'int($1) > old' <"$feed" >"$feed.new"
70 mv "$feed" "$feed.old"
71 mv "$feed.new" "$feed"
72 done
73)
74
75if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
76 main "$@"
77fi