about summary refs log tree commit diff stats
path: root/runsfeed
diff options
context:
space:
mode:
Diffstat (limited to 'runsfeed')
-rwxr-xr-xrunsfeed63
1 files changed, 33 insertions, 30 deletions
diff --git a/runsfeed b/runsfeed index 9c3b330..2068434 100755 --- a/runsfeed +++ b/runsfeed
@@ -1,6 +1,6 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2# Run sfeed 2# Run sfeed
3 3# shellcheck disable=2016
4# set -euo pipefail 4# set -euo pipefail
5 5
6main() { 6main() {
@@ -41,20 +41,24 @@ main() {
41 }' 41 }'
42 logok "Generating RSS" '{ 42 logok "Generating RSS" '{
43 atom "$sfeedpath" >/tmp/feeds.xml && 43 atom "$sfeedpath" >/tmp/feeds.xml &&
44 mv /tmp/feeds.xml "$SFEED_OUTPUT/feeds.xml"; 44 mv /tmp/feeds.xml "$SFEED_OUTPUT/feeds.xml";
45 atom "$sfeedpath" 7 >/tmp/feeds-short.xml && 45 atom "$sfeedpath" 7 >/tmp/feeds-short.xml &&
46 mv /tmp/feeds-short.xml "$SFEED_OUTPUT/feeds-short.xml"; 46 mv /tmp/feeds-short.xml "$SFEED_OUTPUT/feeds-short.xml";
47 }' 47 }'
48 logok "Generating OPML" '{ 48 logok "Generating OPML" '{
49 opml "$sfeedrc" >/tmp/feeds.opml && 49 opml "$sfeedrc" >/tmp/feeds.opml &&
50 mv /tmp/feeds.opml "$SFEED_OUTPUT/feeds.opml"; 50 mv /tmp/feeds.opml "$SFEED_OUTPUT/feeds.opml";
51 }' 51 }'
52 logok "Generating twtxt" '{ 52 logok "Generating twtxt" '{
53 twtxt "$sfeedpath" >/tmp/feeds.txt && 53 twtxt "$sfeedpath" >/tmp/feeds.txt &&
54 mv /tmp/feeds.txt "$SFEED_OUTPUT/feeds.txt"; 54 mv /tmp/feeds.txt "$SFEED_OUTPUT/feeds.txt";
55 }' 55 }'
56 # logok "Archiving old feeds" \ 56 logok "Generating ass" '{
57 # archive "$sfeedpath"/* 57 ass "$sfeedpath" >/tmp/feed.ass &&
58 mv /tmp/feed.ass "$SFEED_OUTPUT/feed.ass";
59 }'
60 logok "Archiving old feeds" \
61 'archive 60 "$sfeedpath"/*'
58 if [ -f /tmp/runsfeed.ok ]; then 62 if [ -f /tmp/runsfeed.ok ]; then
59 echo >&2 'Done.' 63 echo >&2 'Done.'
60 else 64 else
@@ -106,19 +110,25 @@ update() {
106 runcmd sfeed_update_xargs "$@" 110 runcmd sfeed_update_xargs "$@"
107} 111}
108 112
109twtxt() { 113aggregate() {
110 curd="$PWD" 114 curd="$PWD"
111 cd "$1" || return 1 115 cd "$1" || return 1
112 if [ $# -eq 2 ]; then 116 if [ -n "$2" ]; then
113 old="$(($(date +%s) - ($2 * 24 * 3600)))" 117 old="$(($(date +%s) - ($2 * 24 * 3600)))"
114 else 118 else
115 old=0 119 old=0
116 fi 120 fi
117 awk -v old="$old" \ 121 awk -v old="$old" \
118 'BEGIN{FS="\t";OFS="\t";} int($1)>=old{$2="["FILENAME"] "$2;print}' \ 122 'BEGIN{FS="\t";OFS="\t";} int($1)>=old{$2="["FILENAME"] "$2;print}' \
119 * | 123 * | sort -k1,1rn
120 sort -k1,1rn | 124}
121 sfeed_twtxt 125
126ass() {
127 aggregate "$1" "$2" | runcmd sfeed_ass.awk
128}
129
130twtxt() {
131 aggregate "$1" "$2" | sfeed_twtxt
122} 132}
123 133
124opml() { 134opml() {
@@ -130,26 +140,19 @@ html() {
130} 140}
131 141
132atom() ( # atom DIRECTORY [DAYS] 142atom() ( # atom DIRECTORY [DAYS]
133 curd="$PWD" 143 aggregate "$1" "$2" | sfeed_atom
134 cd "$1" || return 1
135 if [ $# -eq 2 ]; then
136 old=$(($(date +%s) - ($2 * 24 * 3600)))
137 else
138 old=0
139 fi
140 awk -F $'\t' -v old="$old" \
141 'BEGIN{OFS="\t"} $1 && int($1)>=old{$2="["FILENAME"] "$2;print}' \
142 * |
143 sort -k1,1rn |
144 sfeed_atom
145) 144)
146 145
147archive() ( # sfeed_archive FEED ... 146archive() ( # sfeed_archive AGE FEED ...
147 age="$1"
148 shift
149 old="$sfeedpath/../sfeed.old.d"
150 mkdir -p "$old"
148 for feed; do 151 for feed; do
149 awk -v old="$(($(date +%s) - (60 * 24 * 3600)))" \ 152 awk -v old="$(($(date +%s) - (age * 24 * 3600)))" \
150 -F '\t' 'int($1) > old' <"$feed" >"$feed.new" 153 -F '\t' 'int($1) > old' <"$feed" >"$feed.new"
151 mv "$feed" "$feed.old" 154 echo mv "$feed" "$old/${feed##*/}" &&
152 mv "$feed.new" "$feed" 155 echo mv "$feed.new" "$feed"
153 done 156 done
154) 157)
155 158