sfeed

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

commit 6e4136753bd0faa15c198118b05c529d96d908c5
parent aed47142611e23b363298bbb534c5cc4bd11a86b
Author: Alvar Penning <post@0x21.biz>
Date:   Mon, 24 Apr 2023 22:01:23 +0200

sfeed_{curses,frames,gopher,html,plain}: SFEED_NEW_MAX_SECS

By introducing the new environment variable $SFEED_NEW_MAX_SECS in all
sfeed_* utilities marking feeds as new based on comparing their age, it
is now possible to override this age limit.

This allows, for example, to be notified about new feeds within the last
hour with

  SFEED_NEW_MAX_SECS=3600 sfeed_plain ~/.sfeed/feeds/*

while creating a beautiful web report for last week's news by

  SFEED_NEW_MAX_SECS=604800 sfeed_html ~/.sfeed/feeds/*

Diffstat:
MREADME | 10++++++----
Msfeed_curses.1 | 4++++
Msfeed_curses.c | 11++++++++---
Msfeed_frames.1 | 7+++++++
Msfeed_frames.c | 15++++++++++++---
Msfeed_gopher.1 | 4++++
Msfeed_gopher.c | 15++++++++++++---
Msfeed_html.1 | 7+++++++
Msfeed_html.c | 15++++++++++++---
Msfeed_plain.1 | 7+++++++
Msfeed_plain.c | 16+++++++++++++---
11 files changed, 92 insertions(+), 19 deletions(-)

diff --git a/README b/README @@ -289,10 +289,12 @@ Just like the other format programs included in sfeed you can run it like this: sfeed_curses < ~/.sfeed/feeds/xkcd -By default sfeed_curses marks the items of the last day as new/bold. To manage -read/unread items in a different way a plain-text file with a list of the read -URLs can be used. To enable this behaviour the path to this file can be -specified by setting the environment variable $SFEED_URL_FILE to the URL file: +By default sfeed_curses marks the items of the last day as new/bold. This limit +might be overridden by setting the environment variable $SFEED_NEW_MAX_SECS to +the desired maximum in seconds. To manage read/unread items in a different way +a plain-text file with a list of the read URLs can be used. To enable this +behaviour the path to this file can be specified by setting the environment +variable $SFEED_URL_FILE to the URL file: export SFEED_URL_FILE="$HOME/.sfeed/urls" [ -f "$SFEED_URL_FILE" ] || touch "$SFEED_URL_FILE" diff --git a/sfeed_curses.1 b/sfeed_curses.1 @@ -30,6 +30,7 @@ arguments are specified then the data is read from stdin and the feed name is .Pp Items with a timestamp from the last day compared to the system time at the time of loading the feed are marked as new and bold. +This value might be overridden through environment variables. There is also an alternative mode available to mark items as read by matching it against a list of URLs from a plain-text file. Items with an enclosure are marked with a @ symbol. @@ -207,6 +208,9 @@ SIGWINCH. Read and process a sequence of keys as input commands from this environment variable first, afterwards it reads from the tty as usual. This can be useful to automate certain actions at the start. +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. .It Ev SFEED_PIPER A program where the whole TAB-Separated Value line is piped to. By default this is "sfeed_content". diff --git a/sfeed_curses.c b/sfeed_curses.c @@ -191,6 +191,7 @@ static int plumberia = 0; /* env variable: $SFEED_PLUMBER_INTERACTIVE */ static int piperia = 1; /* env variable: $SFEED_PIPER_INTERACTIVE */ static int yankeria = 0; /* env variable: $SFEED_YANKER_INTERACTIVE */ static int lazyload = 0; /* env variable: $SFEED_LAZYLOAD */ +static int newmaxsecs = 86400; /* env variable: $SFEED_NEW_MAX_SECS */ int ttywritef(const char *fmt, ...) @@ -1322,8 +1323,7 @@ feeds_load(struct feed *feeds, size_t nfeeds) errno = 0; if ((comparetime = time(NULL)) == (time_t)-1) die("time"); - /* 1 day is old news */ - comparetime -= 86400; + comparetime -= newmaxsecs; for (i = 0; i < nfeeds; i++) { f = &feeds[i]; @@ -1967,7 +1967,7 @@ main(int argc, char *argv[]) struct pane *p; struct feed *f; struct row *row; - char *name, *tmp; + char *name, *tmp, *endptr; char *search = NULL; /* search text */ int button, ch, fd, i, keymask, release, x, y; off_t pos; @@ -1997,6 +1997,11 @@ main(int argc, char *argv[]) markunreadcmd = tmp; if ((tmp = getenv("SFEED_LAZYLOAD"))) lazyload = !strcmp(tmp, "1"); + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + newmaxsecs = (int) strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || newmaxsecs <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + } urlfile = getenv("SFEED_URL_FILE"); /* can be NULL */ cmdenv = getenv("SFEED_AUTOCMD"); /* can be NULL */ diff --git a/sfeed_frames.1 b/sfeed_frames.1 @@ -23,6 +23,7 @@ file is not written. Items with a timestamp from the last day compared to the system time at the time of formatting are counted and marked as new. Items are marked as new using a bold markup. +This value might be overridden through environment variables. .Pp There is an example style.css stylesheet file included in the distribution. .Sh FILES WRITTEN @@ -37,6 +38,12 @@ feeds. The HTML file of the menu frame which contains navigation "anchor" links (like "#feedname") to the feed names in items.html. .El +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width Ds +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. +.El .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/sfeed_frames.c b/sfeed_frames.c @@ -77,8 +77,9 @@ int main(int argc, char *argv[]) { FILE *fpindex, *fpitems, *fpmenu = NULL, *fp; - char *name; + char *name, *tmp, *endptr; int i, showsidebar = (argc > 1); + long l; struct feed *f; if (pledge("stdio rpath wpath cpath", NULL) == -1) @@ -89,8 +90,16 @@ main(int argc, char *argv[]) if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } /* write main index page */ if (!(fpindex = fopen("index.html", "wb"))) diff --git a/sfeed_gopher.1 b/sfeed_gopher.1 @@ -32,6 +32,7 @@ written to stdout and no files are written. .Pp Items with a timestamp from the last day compared to the system time at the time of formatting are counted and marked as new. +This value might be overridden through environment variables. Items are marked as new with the prefix "N" at the start of the line. .Sh ENVIRONMENT .Bl -tag -width Ds @@ -45,6 +46,9 @@ The default is "127.0.0.1". .It Ev SFEED_GOPHER_PORT This environment variable can be used as the Gopher Port field. The default is "70". +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. .El .Sh EXIT STATUS .Ex -std diff --git a/sfeed_gopher.c b/sfeed_gopher.c @@ -122,8 +122,9 @@ int main(int argc, char *argv[]) { FILE *fpitems, *fpindex, *fp; - char *name, *p; + char *name, *p, *tmp, *endptr; int i; + long l; if (argc == 1) { if (pledge("stdio", NULL) == -1) @@ -139,8 +140,16 @@ main(int argc, char *argv[]) if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } if ((p = getenv("SFEED_GOPHER_HOST"))) host = p; diff --git a/sfeed_html.1 b/sfeed_html.1 @@ -26,9 +26,16 @@ is empty. .Pp Items with a timestamp from the last day compared to the system time at the time of formatting are counted and marked as new. +This value might be overridden through environment variables. Items are marked as new using a bold markup. .Pp There is an example style.css stylesheet file included in the distribution. +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width Ds +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. +.El .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/sfeed_html.c b/sfeed_html.c @@ -78,9 +78,10 @@ int main(int argc, char *argv[]) { struct feed *f; - char *name; + char *name, *tmp, *endptr; FILE *fp; int i; + long l; if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) err(1, "pledge"); @@ -89,8 +90,16 @@ main(int argc, char *argv[]) err(1, "calloc"); if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } fputs("<!DOCTYPE HTML>\n" "<html>\n" diff --git a/sfeed_plain.1 b/sfeed_plain.1 @@ -26,6 +26,7 @@ is empty. .Pp Items with a timestamp from the last day compared to the system time at the time of formatting are marked as new. +This value might be overridden through environment variables. Items are marked as new with the prefix "N" at the start of the line. .Pp .Nm @@ -39,6 +40,12 @@ per rune, using .Xr mbtowc 3 and .Xr wcwidth 3 . +.Sh ENVIRONMENT VARIABLES +.Bl -tag -width Ds +.It Ev SFEED_NEW_MAX_SECS +Overwrite the maximum age in seconds to mark feeds as new. +By default this is 86400, which equals one day. +.El .Sh EXIT STATUS .Ex -std .Sh EXAMPLES diff --git a/sfeed_plain.c b/sfeed_plain.c @@ -2,6 +2,7 @@ #include <locale.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <time.h> @@ -52,8 +53,9 @@ int main(int argc, char *argv[]) { FILE *fp; - char *name; + char *name, *tmp, *endptr; int i; + long l; if (pledge("stdio rpath", NULL) == -1) err(1, "pledge"); @@ -65,8 +67,16 @@ main(int argc, char *argv[]) if ((comparetime = time(NULL)) == (time_t)-1) errx(1, "time"); - /* 1 day is old news */ - comparetime -= 86400; + + if ((tmp = getenv("SFEED_NEW_MAX_SECS"))) { + l = strtol(tmp, &endptr, 10); + if (*tmp == '\0' || *endptr != '\0' || l <= 0) + err(1, "cannot parse $SFEED_NEW_MAX_SECS"); + comparetime -= l; + } else { + /* 1 day is old news */ + comparetime -= 86400; + } if (argc == 1) { printfeed(stdin, "");