Add min and max date support

This commit is contained in:
Jaidyn Ann 2020-07-07 17:42:12 -05:00
parent dd51380e6f
commit 7e6b2d5671
6 changed files with 54 additions and 13 deletions

View File

@ -1,6 +1,7 @@
#ifndef CONFIG_H
#define CONFIG_H
#include <DateTime.h>
#include <String.h>
#include <StorageKit.h>
@ -12,6 +13,9 @@ public:
BString outDir;
BList targetFeeds; // file or url
BDateTime minDate;
BDateTime maxDate;
Config ( );
};

View File

@ -5,6 +5,7 @@
#include "Item.h"
#include "parsing.h"
#include "Config.h"
#include "Util.h"
#include "Pogger.h"
#include <StorageKit.h>
@ -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;
}
}

View File

@ -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"
;

View File

@ -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 )
{

View File

@ -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* );

View File

@ -3,6 +3,7 @@
#include <tinyxml2.h>
#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