sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 6446070da557bf8b56fa44b2bbdc4690edf490a9
parent 68a48bea8231afdf3f5e533a07bffeb1dc39f875
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed, 22 Aug 2018 16:23:52 +0200

add sfeed_twtxt format program: format to a twtxt feed

Diffstat:
MMakefile | 1+
MREADME | 3++-
Asfeed_twtxt.1 | 30++++++++++++++++++++++++++++++
Asfeed_twtxt.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -11,6 +11,7 @@ BIN = \ sfeed_opml_import\ sfeed_plain\ sfeed_tail\ + sfeed_twtxt\ sfeed_web\ sfeed_xmlenc SCRIPTS = \ diff --git a/README b/README @@ -111,7 +111,8 @@ sfeed_opml_export - Generate an OPML XML file from a sfeedrc config file. sfeed_opml_import - Generate a sfeedrc config file from an OPML XML file. sfeed_mbox - Format feed data (TSV) to mbox. sfeed_plain - Format feed data (TSV) to a plain-text list. -sfeed_tail - format unseen feed data (TSV) to a plain-text list. +sfeed_tail - Format unseen feed data (TSV) to a plain-text list. +sfeed_twtxt - Format feed data (TSV) to a twtxt feed. sfeed_update - Update feeds and merge with old feeds in the directory $HOME/.sfeed/feeds by default. sfeed_web - Find urls to RSS/Atom feed from a webpage. diff --git a/sfeed_twtxt.1 b/sfeed_twtxt.1 @@ -0,0 +1,30 @@ +.Dd August 22, 2018 +.Dt SFEED_TWTXT 1 +.Os +.Sh NAME +.Nm sfeed_twtxt +.Nd format feed data to a twtxt feed +.Sh SYNOPSIS +.Nm +.Op Ar file... +.Sh DESCRIPTION +.Nm +formats feed data (TSV) from +.Xr sfeed 1 +from stdin or +.Ar file +to stdout as a twtxt feed. +If one or more +.Ar file +are specified, the basename of the +.Ar file +is used as the feed name in the output. +If no +.Ar file +parameters are specified and so the data is read from stdin the feed name +is empty. +.Sh SEE ALSO +.Xr sfeed 1 , +.Xr sfeed_plain 1 +.Sh AUTHORS +.An Hiltjo Posthuma Aq Mt hiltjo@codemadness.org diff --git a/sfeed_twtxt.c b/sfeed_twtxt.c @@ -0,0 +1,76 @@ +#include <ctype.h> +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#include "util.h" + +static char *line; +static size_t linesize; + +static void +printfeed(FILE *fp, const char *feedname) +{ + char *fields[FieldLast]; + struct tm *tm; + time_t parsedtime; + ssize_t linelen; + + while ((linelen = getline(&line, &linesize, fp)) > 0) { + if (line[linelen - 1] == '\n') + line[--linelen] = '\0'; + if (!parseline(line, fields)) + break; + + parsedtime = 0; + if (strtotime(fields[FieldUnixTimestamp], &parsedtime)) + continue; + if (!(tm = gmtime(&parsedtime))) + err(1, "localtime"); + + fprintf(stdout, "%04d-%02d-%02dT%02d:%02d:%02dZ\t", + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec); + if (feedname[0]) + printf("[%s] ", feedname); + fputs(fields[FieldTitle], stdout); + if (fields[FieldLink][0]) { + fputs(" @<", stdout); + if (fields[FieldAuthor][0]) { + fputs(fields[FieldAuthor], stdout); + fputs(" ", stdout); + } + fputs(fields[FieldLink], stdout); + fputs(">", stdout); + } + putchar('\n'); + } +} + +int +main(int argc, char *argv[]) +{ + FILE *fp; + char *name; + int i; + + if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1) + err(1, "pledge"); + + if (argc == 1) { + printfeed(stdin, ""); + } else { + for (i = 1; i < argc; i++) { + if (!(fp = fopen(argv[i], "r"))) + err(1, "fopen: %s", argv[i]); + name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i]; + printfeed(fp, name); + if (ferror(fp)) + err(1, "ferror: %s", argv[i]); + fclose(fp); + } + } + return 0; +}