diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2017-12-16 12:09:31 +0100 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2017-12-16 12:09:31 +0100 |
commit | a720526f1b490bb84eb357ce4b4114e11ccca3ec (patch) | |
tree | 6d96bf3677a6cfc0ddacdb1fec8674eeafe3a74e /sfeed_update | |
parent | dd00baa7ecde11cd7a6858203ee372db3b6dea60 (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-x | sfeed_update | 21 |
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 |