diff --git a/src/Config.h b/src/Config.h index c4ecf9e..eaf5a94 100644 --- a/src/Config.h +++ b/src/Config.h @@ -1,6 +1,7 @@ #ifndef CONFIG_H #define CONFIG_H +#include #include #include @@ -12,6 +13,9 @@ public: BString outDir; BList targetFeeds; // file or url + BDateTime minDate; + BDateTime maxDate; + Config ( ); }; diff --git a/src/Pogger.cpp b/src/Pogger.cpp index 3e84e72..faf4cf1 100644 --- a/src/Pogger.cpp +++ b/src/Pogger.cpp @@ -5,6 +5,7 @@ #include "Item.h" #include "parsing.h" #include "Config.h" +#include "Util.h" #include "Pogger.h" #include @@ -36,7 +37,9 @@ int invocation ( int argc, char** argv, Config** cfgPtr ) { Config* cfg = *(cfgPtr); - bool suicide = false; + BDateTime maxDate; + BDateTime minDate; + static struct option sLongOptions[] = { { "help", no_argument, 0, 'h' }, { "verbose", no_argument, 0, 'v' }, @@ -48,7 +51,7 @@ invocation ( int argc, char** argv, Config** cfgPtr ) while (true) { opterr = 0; - int c = getopt_long(argc, argv, "+hvDm:O:", sLongOptions, NULL); + int c = getopt_long(argc, argv, "+hvDm:O:T:t:", sLongOptions, NULL); switch (c) { case -1: @@ -57,10 +60,28 @@ invocation ( int argc, char** argv, Config** cfgPtr ) case 'h': return usage(); case 'm': - cfg->mimetype = BString(optarg); + cfg->mimetype = BString( optarg ); + break; + case 't': + minDate = dateRfc3339ToBDate( optarg ); + if ( minDate != NULL ) + cfg->minDate = minDate; + else { + fprintf(stderr, "Invalid date format for `-%c'.\n", optopt); + return 2; + } + break; + case 'T': + maxDate = dateRfc3339ToBDate( optarg ); + if ( maxDate != NULL ) + cfg->maxDate = maxDate; + else { + fprintf(stderr, "Invalid date format for `-%c'.\n", optopt); + return 2; + } break; case 'O': - cfg->outDir = BString(optarg); + cfg->outDir = BString( optarg ); break; case 'v': cfg->verbose = true; @@ -70,10 +91,10 @@ invocation ( int argc, char** argv, Config** cfgPtr ) break; case '?': if ( optopt == 'O' || optopt == 'm' ) - fprintf( stderr, "Option `-%c` requires an argument.\n\n", + fprintf( stderr, "Option `-%c` requires an argument.\n", optopt ); else - fprintf( stderr, "Unknown option `-%c`.\n\n", optopt ); + fprintf( stderr, "Unknown option `-%c`.\n", optopt ); return 2; } } diff --git a/src/Pogger.h b/src/Pogger.h index 6c9f64f..514aa9d 100644 --- a/src/Pogger.h +++ b/src/Pogger.h @@ -38,13 +38,11 @@ BString usageMsg = "\n" "Both -t and -T use the ISO 8601 format for specifying datetimes:\n" " YYYY-MM-DDTHH:MM:SS - 2020-01-01T07:07:07\n" - "You can leave out seconds, minutes, or hours, but YMD are required.\n" "\n" "NOTE: This message doesn't reflect reality. This is more of a spec of\n" - " what I hope this program will be. As of now -t and -T aren't\n" - " implemented, and running %app% without a file/url free-argument\n" - " is invalid, as the daemon isn't implemented at all. As such,\n" - " -D is also non-functional.\n" + " what I hope this program will be. As of now, running %app%\n" + " without a file/url free-argument is invalid, as the daemon\n" + " isn't implemented at all. As such, -D is also non-functional.\n" " But it sure can turn an XML feed into files! Lol.\n" ; diff --git a/src/Util.cpp b/src/Util.cpp index 8a9172a..98d6cd2 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -58,6 +58,20 @@ dateTo3339String ( BDateTime dt ) // ---------------------------------------------------------------------------- +bool +withinDateRange ( BDateTime minDate, BDateTime nowDate, BDateTime maxDate ) +{ + if ( minDate != NULL && nowDate != NULL && maxDate != NULL ) + return ( minDate < nowDate && nowDate < maxDate ); + if ( minDate != NULL && nowDate != NULL ) + return ( minDate < nowDate ); + if ( maxDate != NULL && nowDate != NULL ) + return ( nowDate < maxDate ); + return true; +} + +// ---------------------------------------------------------------------------- + int32 webFetch ( char* strUrl, BDataIO* reply ) { diff --git a/src/Util.h b/src/Util.h index ba16471..21621a8 100644 --- a/src/Util.h +++ b/src/Util.h @@ -12,6 +12,7 @@ BDateTime stringDateToBDate ( const char*, const char* ); BString dateTo3339String ( BDateTime ); +bool withinDateRange ( BDateTime, BDateTime, BDateTime ); int32 webFetch ( BUrl, BDataIO* ); int32 webFetch ( char*, BDataIO* ); diff --git a/src/parsing.cpp b/src/parsing.cpp index 4bdf480..635cf9b 100644 --- a/src/parsing.cpp +++ b/src/parsing.cpp @@ -3,6 +3,7 @@ #include #include "Channel.h" #include "Item.h" +#include "Util.h" #include "parsing.h" @@ -65,7 +66,8 @@ rssItemParse ( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xitem ) if (cfg->verbose ) printf("\t%s\n", newItem->title.String()); - chan->items.AddItem( newItem ); + if ( withinDateRange( cfg->minDate, newItem->pubDate, cfg->maxDate ) ) + chan->items.AddItem( newItem ); } void @@ -159,7 +161,8 @@ atomEntryParse ( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xentry ) if ( cfg->verbose ) printf("\t%s\n", newItem->title.String()); - chan->items.AddItem( newItem ); + if ( withinDateRange( cfg->minDate, newItem->pubDate, cfg->maxDate ) ) + chan->items.AddItem( newItem ); } void