summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2017-12-24 13:13:17 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2017-12-24 13:16:32 +0100
commit3be9c1d71b0afd455381a3f166a8deb4b55a2c9f (patch)
treefe22e07adb09ad8d89a8a834adf68fb02ad525d4
parent293d1cec14439566ceed181fb397381d471a6c66 (diff)
sfeed_update: merge improvements
does not sort all entries by datetime descending anymore. Now only new entries are appending in a datetime ascending order.
-rw-r--r--README1
-rwxr-xr-xsfeed_update20
2 files changed, 14 insertions, 7 deletions
diff --git a/README b/README
index c949f56..fc97e34 100644
--- a/README
+++ b/README
@@ -74,6 +74,7 @@ Optional dependencies
- make(1) (for Makefile).
- POSIX sh(1),
used by sfeed_update(1) and sfeed_opml_export(1).
+- awk(1), used by sfeed_update(1).
- curl(1) binary: http://curl.haxx.se/ ,
used by sfeed_update(1), can be replaced with any tool like wget(1),
OpenBSD ftp(1).
diff --git a/sfeed_update b/sfeed_update
index cf384d1..e280d22 100755
--- a/sfeed_update
+++ b/sfeed_update
@@ -31,10 +31,14 @@ loadconfig() {
# merge raw files.
# merge(oldfile, newfile)
merge() {
- # unique sort by id, title, link.
- # order by timestamp (desc).
- (sort -t ' ' -u -k6,6 -k2,2 -k3,3 "$1" "$2" 2>/dev/null) |
- sort -t ' ' -k1rn,1
+ # unique check by id, title, link.
+ # print only new entries in newfile.
+ # order new items by timestamp (asc).
+ (sed 's@^@O @' "$1"
+ sed 's@^@N @' "$2") | \
+ awk '!x[$7 " " $3 " " $4]++ && $1 == "N"' 2>/dev/null | \
+ cut -f 2- | \
+ sort -t ' ' -k1n,1
}
# fetch a feed via HTTP/HTTPS etc.
@@ -88,10 +92,12 @@ feed() {
# if file exists, merge
if [ -e "${sfeedfile}" ]; then
merge "${sfeedfile}" "${tmpfeedfile}" > "${sfeedfilenew}"
- # overwrite old file with updated file
- mv "${sfeedfilenew}" "${sfeedfile}"
+
+ # append new entries to feed file.
+ cat "${sfeedfilenew}" >> "${sfeedfile}"
+ rm -f "${sfeedfilenew}"
else
- merge "/dev/null" "${tmpfeedfile}" > "${sfeedfile}"
+ mv "${tmpfeedfile}" "${sfeedfile}"
fi
fi) &
}