summaryrefslogtreecommitdiff
path: root/sfeed_update
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2017-12-16 12:09:31 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2017-12-16 12:09:31 +0100
commita720526f1b490bb84eb357ce4b4114e11ccca3ec (patch)
tree6d96bf3677a6cfc0ddacdb1fec8674eeafe3a74e /sfeed_update
parentdd00baa7ecde11cd7a6858203ee372db3b6dea60 (diff)
sfeed_update: improvements
- clarify code and improve linewrapping. - translate characters in filename (allow /) - add feedname as separate feed name field. - change in which order priority the field is checked.
Diffstat (limited to 'sfeed_update')
-rwxr-xr-xsfeed_update21
1 files changed, 13 insertions, 8 deletions
diff --git a/sfeed_update b/sfeed_update
index 797ba6f..cf384d1 100755
--- a/sfeed_update
+++ b/sfeed_update
@@ -31,9 +31,9 @@ loadconfig() {
# merge raw files.
# merge(oldfile, newfile)
merge() {
- # unique sort by id, link, title.
+ # unique sort by id, title, link.
# order by timestamp (desc).
- (sort -t ' ' -u -k6,6 -k3,3 -k2,2 "$1" "$2" 2>/dev/null) |
+ (sort -t ' ' -u -k6,6 -k2,2 -k3,3 "$1" "$2" 2>/dev/null) |
sort -t ' ' -k1rn,1
}
@@ -63,21 +63,26 @@ convertencoding() {
# feed(name, feedurl, [basesiteurl], [encoding])
feed() {
(name="$1"
- tmpfeedfile="${sfeedtmpdir}/${name}"
+ filename="$(printf '%s' "$1" | sed -E 's@[^a-zA-Z0-9]+@_@g')"
+ feedurl="$2"
+ basesiteurl="$3"
+ tmpfeedfile="${sfeedtmpdir}/${filename}"
tmpencfile=""
encoding="$4"
- sfeedfile="${sfeedpath}/$1"
+ sfeedfile="${sfeedpath}/${filename}"
if [ ! "${encoding}" = "" ]; then
- fetchfeed "$2" "$1" "${sfeedfile}" | convertencoding "${encoding}" "utf-8"
+ fetchfeed "${feedurl}" "${name}" "${sfeedfile}" | \
+ convertencoding "${encoding}" "utf-8"
else # detect encoding.
tmpencfile="${tmpfeedfile}.enc"
- fetchfeed "$2" "$1" "${sfeedfile}" > "${tmpencfile}"
+ fetchfeed "${feedurl}" "${name}" "${sfeedfile}" > "${tmpencfile}"
detectenc=$(sfeed_xmlenc < "${tmpencfile}")
convertencoding "${detectenc}" "utf-8" < "${tmpencfile}"
- fi | sfeed "$3" > "${tmpfeedfile}"
+ fi | sfeed "${basesiteurl}" | \
+ awk -v "n=${name}" '{ print $0 " " n }' > "${tmpfeedfile}"
# get new data and merge with old.
- sfeedfilenew="${sfeedpath}/${name}.new"
+ sfeedfilenew="${sfeedpath}/${filename}.new"
# new feed data is non-empty.
if [ -s "${tmpfeedfile}" ]; then
# if file exists, merge