Add min and max date support
This commit is contained in:
parent
dd51380e6f
commit
7e6b2d5671
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#include <DateTime.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <StorageKit.h>
|
#include <StorageKit.h>
|
||||||
|
|
||||||
|
@ -12,6 +13,9 @@ public:
|
||||||
BString outDir;
|
BString outDir;
|
||||||
BList targetFeeds; // file or url
|
BList targetFeeds; // file or url
|
||||||
|
|
||||||
|
BDateTime minDate;
|
||||||
|
BDateTime maxDate;
|
||||||
|
|
||||||
Config ( );
|
Config ( );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "Item.h"
|
#include "Item.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include "Util.h"
|
||||||
#include "Pogger.h"
|
#include "Pogger.h"
|
||||||
|
|
||||||
#include <StorageKit.h>
|
#include <StorageKit.h>
|
||||||
|
@ -36,7 +37,9 @@ int
|
||||||
invocation ( int argc, char** argv, Config** cfgPtr )
|
invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
{
|
{
|
||||||
Config* cfg = *(cfgPtr);
|
Config* cfg = *(cfgPtr);
|
||||||
bool suicide = false;
|
BDateTime maxDate;
|
||||||
|
BDateTime minDate;
|
||||||
|
|
||||||
static struct option sLongOptions[] = {
|
static struct option sLongOptions[] = {
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
{ "verbose", no_argument, 0, 'v' },
|
{ "verbose", no_argument, 0, 'v' },
|
||||||
|
@ -48,7 +51,7 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
opterr = 0;
|
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) {
|
switch (c) {
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -57,10 +60,28 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage();
|
return usage();
|
||||||
case 'm':
|
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;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
cfg->outDir = BString(optarg);
|
cfg->outDir = BString( optarg );
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
cfg->verbose = true;
|
cfg->verbose = true;
|
||||||
|
@ -70,10 +91,10 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
if ( optopt == 'O' || optopt == 'm' )
|
if ( optopt == 'O' || optopt == 'm' )
|
||||||
fprintf( stderr, "Option `-%c` requires an argument.\n\n",
|
fprintf( stderr, "Option `-%c` requires an argument.\n",
|
||||||
optopt );
|
optopt );
|
||||||
else
|
else
|
||||||
fprintf( stderr, "Unknown option `-%c`.\n\n", optopt );
|
fprintf( stderr, "Unknown option `-%c`.\n", optopt );
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,13 +38,11 @@ BString usageMsg =
|
||||||
"\n"
|
"\n"
|
||||||
"Both -t and -T use the ISO 8601 format for specifying datetimes:\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"
|
" 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"
|
"\n"
|
||||||
"NOTE: This message doesn't reflect reality. This is more of a spec of\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"
|
" what I hope this program will be. As of now, running %app%\n"
|
||||||
" implemented, and running %app% without a file/url free-argument\n"
|
" without a file/url free-argument is invalid, as the daemon\n"
|
||||||
" is invalid, as the daemon isn't implemented at all. As such,\n"
|
" isn't implemented at all. As such, -D is also non-functional.\n"
|
||||||
" -D is also non-functional.\n"
|
|
||||||
" But it sure can turn an XML feed into files! Lol.\n"
|
" But it sure can turn an XML feed into files! Lol.\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
14
src/Util.cpp
14
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
|
int32
|
||||||
webFetch ( char* strUrl, BDataIO* reply )
|
webFetch ( char* strUrl, BDataIO* reply )
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,7 @@ BDateTime stringDateToBDate ( const char*, const char* );
|
||||||
|
|
||||||
BString dateTo3339String ( BDateTime );
|
BString dateTo3339String ( BDateTime );
|
||||||
|
|
||||||
|
bool withinDateRange ( BDateTime, BDateTime, BDateTime );
|
||||||
|
|
||||||
int32 webFetch ( BUrl, BDataIO* );
|
int32 webFetch ( BUrl, BDataIO* );
|
||||||
int32 webFetch ( char*, BDataIO* );
|
int32 webFetch ( char*, BDataIO* );
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
#include "Channel.h"
|
#include "Channel.h"
|
||||||
#include "Item.h"
|
#include "Item.h"
|
||||||
|
#include "Util.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +66,7 @@ rssItemParse ( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xitem )
|
||||||
if (cfg->verbose )
|
if (cfg->verbose )
|
||||||
printf("\t%s\n", newItem->title.String());
|
printf("\t%s\n", newItem->title.String());
|
||||||
|
|
||||||
|
if ( withinDateRange( cfg->minDate, newItem->pubDate, cfg->maxDate ) )
|
||||||
chan->items.AddItem( newItem );
|
chan->items.AddItem( newItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +161,7 @@ atomEntryParse ( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xentry )
|
||||||
if ( cfg->verbose )
|
if ( cfg->verbose )
|
||||||
printf("\t%s\n", newItem->title.String());
|
printf("\t%s\n", newItem->title.String());
|
||||||
|
|
||||||
|
if ( withinDateRange( cfg->minDate, newItem->pubDate, cfg->maxDate ) )
|
||||||
chan->items.AddItem( newItem );
|
chan->items.AddItem( newItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue