From 264f8a4a94fb366f90166e66300a82f513aaf515 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Fri, 17 Nov 2023 16:04:08 -0600 Subject: [PATCH] Add a custom sfeedrc for getting only new posts --- README.md | 25 +++++++++------------ sfeedrc.example | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 sfeedrc.example diff --git a/README.md b/README.md index 35e5a2f..8d1149b 100644 --- a/README.md +++ b/README.md @@ -20,20 +20,15 @@ You’ve done it! ## Configuration ### sfeed -We need to create a config file and feed directory for sfeed — they can be anywhere, your choice. +We need to create a config file and feed directory for sfeed_update. +You can use the sfeedrc.example file in this repo as a base for your own config file. ``` $ mkdir ~/.config/sfeed/ -$ cat > ~/.config/sfeed/config < /dev/null)" + if test -z "$previous_max_date"; then + previous_max_date=0 + fi + + # Update the date of the last-processed post. + local latest_date="$(latest_date "$newfile")" + attr -qs sfeed_latest -V "$latest_date" "$oldfile" 2> /dev/null + + # Output only new and unprocessed posts. + after_date "$newfile" "$previous_max_date" +} + + +# Given an sfeed file, this returns the date of the latest post (in seconds +# since the UNIX epoch). +latest_date() { + local file="$1" + awk -F '\t' \ + '$1 > latest { latest = $1 } END { print latest }' \ + "$file" +} + + +# This outputs only lines of an sfeed file with a date after the given min_date +# (in seconds since UNIX epoch). +after_date() { + local file="$1" + local min_date="$2" + awk -F '\t' -v min_date="$min_date" \ + '$1 > min_date { print $0 }' \ + "$file" +}