sfeed

Simple RSS and Atom feed parser
git clone https://git.sinitax.com/codemadness/sfeed
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit a720526f1b490bb84eb357ce4b4114e11ccca3ec
parent dd00baa7ecde11cd7a6858203ee372db3b6dea60
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat, 16 Dec 2017 12:09:31 +0100

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:
Msfeed_update | 21+++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)

diff --git 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