diff --git a/README.txt b/README.txt index 5a9b9ff..67c6da6 100644 --- a/README.txt +++ b/README.txt @@ -97,7 +97,7 @@ Both -t and -T use the ISO 8601 format for specifying datetimes: NOTE: This message doesn't reflect reality. This is more of a spec of what I hope this program will be. As of now, running Pogger without a file/url free-argument is invalid, as the daemon - isn't implemented at all. As such, -D -u and -C are non-functional. + isn't implemented at all. As such, -D and -C are non-functional. But it sure can turn an XML feed into files! Lol. diff --git a/src/AtomFeed.cpp b/src/AtomFeed.cpp index 6a57a20..92ab94e 100644 --- a/src/AtomFeed.cpp +++ b/src/AtomFeed.cpp @@ -19,18 +19,26 @@ AtomFeed::AtomFeed ( BString path, Config* cfg ) void AtomFeed::Parse ( Config* cfg ) { + BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY ); entries = BList(); tinyxml2::XMLDocument xml; xml.LoadFile( filePath.String() ); + time_t tt_lastDate = 0; + BDateTime attrLastDate = BDateTime(); + + feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); + if ( tt_lastDate > 0 && cfg->minDate == NULL && cfg->updateFeeds == true ) { + attrLastDate.SetTime_t( tt_lastDate ); + cfg->minDate = attrLastDate; + } tinyxml2::XMLElement* xfeed = xml.FirstChildElement("feed"); RootParse( cfg, xfeed ); ParseEntries( cfg, xfeed ); - time_t tt_lastDate = lastDate.Time_t(); - BFile* cacheFile = new BFile( filePath, B_READ_WRITE ); - cacheFile->WriteAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); + tt_lastDate = lastDate.Time_t(); + feedFile->WriteAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); } void @@ -80,7 +88,7 @@ AtomFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xentry ) set = newEntry->SetDate( xentry->FirstChildElement("updated") ); if ( !set ) set = newEntry->SetDate( xentry->FirstChildElement("published") ); - if ( lastDate != NULL || lastDate < newEntry->date ) + if ( lastDate == NULL || lastDate < newEntry->date ) lastDate = newEntry->date; if ( xcontent ) { @@ -88,11 +96,7 @@ AtomFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xentry ) newEntry->SetContent( xprinter.CStr() ); } - if ( cfg->verbose ) - printf("\t%s\n", newEntry->title.String()); - - if ( withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) ) - entries.AddItem( newEntry ); + AddEntry( cfg, newEntry ); } void diff --git a/src/Feed.cpp b/src/Feed.cpp index aadd15a..84f7a36 100644 --- a/src/Feed.cpp +++ b/src/Feed.cpp @@ -42,6 +42,8 @@ BString Feed::FetchRemoteFeed ( BString givenPath, Config* cfg ) { BUrl givenUrl = BUrl( givenPath ); + time_t tt_lastDate = 0; + BDateTime* lastDate = new BDateTime(); BString* newHash = new BString(); char oldHash[41]; @@ -53,8 +55,7 @@ Feed::FetchRemoteFeed ( BString givenPath, Config* cfg ) filename.Append(splitName); BFile* cacheFile = new BFile( filename, B_READ_WRITE | B_CREATE_FILE ); - cacheFile->ReadAttr( "LastHash", B_STRING_TYPE, 0, - oldHash, 41 ); + cacheFile->ReadAttr( "LastHash", B_STRING_TYPE, 0, oldHash, 41 ); if ( cfg->verbose ) printf( "Saving %s...\n", givenPath.String() ); @@ -109,6 +110,18 @@ Feed::xmlCountSiblings ( tinyxml2::XMLElement* xsibling, const char* sibling_nam // ---------------------------------------------------------------------------- +bool +Feed::AddEntry ( Config* cfg, Entry* newEntry ) +{ + if ( !withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) ) + return false; + + if ( cfg->verbose == true ) + printf( "\t%s\n", newEntry->title.String() ); + entries.AddItem( newEntry ); + return true; +} + bool Feed::SetTitle ( const char* titleStr ) { if ( titleStr != NULL ) title = BString( titleStr ); else return false; @@ -150,7 +163,6 @@ bool Feed::SetDate ( const char* dateCStr ) { } bool Feed::SetDate ( tinyxml2::XMLElement* elem ) { if ( elem != NULL ) return SetDate( elem->GetText() ); - else return false; } diff --git a/src/Feed.h b/src/Feed.h index 2b67c03..c61d052 100644 --- a/src/Feed.h +++ b/src/Feed.h @@ -6,6 +6,7 @@ #include #include #include +#include "Entry.h" #include "Config.h" class Feed { @@ -26,6 +27,7 @@ public: void Parse ( Config* ); + bool AddEntry ( Config*, Entry* ); bool SetTitle ( const char* ); bool SetTitle ( tinyxml2::XMLElement* ); bool SetDesc ( const char* ); diff --git a/src/Pogger.cpp b/src/Pogger.cpp index 10c82cf..3165a7e 100644 --- a/src/Pogger.cpp +++ b/src/Pogger.cpp @@ -52,12 +52,13 @@ invocation ( int argc, char** argv, Config** cfgPtr ) { "after", required_argument, 0, 'T' }, { "output", required_argument, 0, 'O' }, { "foreground", no_argument, 0, 'D' }, + { "update", no_argument, 0, 'u' }, { 0, 0, 0, 0 } }; while (true) { opterr = 0; - int c = getopt_long(argc, argv, "+hsvDm:O:T:t:c:C:", sLongOptions, NULL); + int c = getopt_long(argc, argv, "+hsuvDm:O:T:t:c:C:", sLongOptions, NULL); switch (c) { case -1: @@ -94,6 +95,9 @@ invocation ( int argc, char** argv, Config** cfgPtr ) case 'O': cfg->outDir = BString( optarg ); break; + case 'u': + cfg->updateFeeds = true; + break; case 'v': cfg->verbose = true; break; diff --git a/src/RssFeed.cpp b/src/RssFeed.cpp index 1e0b297..3181bd3 100644 --- a/src/RssFeed.cpp +++ b/src/RssFeed.cpp @@ -19,18 +19,27 @@ RssFeed::RssFeed ( BString path, Config* cfg ) void RssFeed::Parse ( Config* cfg ) { - entries = BList(); + BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY ); tinyxml2::XMLDocument xml; - xml.LoadFile( filePath.String() ); + entries = BList(); + time_t tt_lastDate = 0; + BDateTime attrLastDate = BDateTime(); + + feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); + if ( tt_lastDate > 0 && cfg->minDate == NULL && cfg->updateFeeds == true ) { + attrLastDate.SetTime_t( tt_lastDate ); + cfg->minDate = attrLastDate; + } + + xml.LoadFile( filePath.String() ); tinyxml2::XMLElement* xchan = xml.FirstChildElement("rss")->FirstChildElement("channel"); RootParse( cfg, xchan ); ParseEntries( cfg, xchan ); - time_t tt_lastDate = lastDate.Time_t(); - BFile* cacheFile = new BFile( filePath, B_READ_WRITE ); - cacheFile->WriteAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); + tt_lastDate = lastDate.Time_t(); + feedFile->WriteAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); } // ------------------------------------- @@ -59,14 +68,10 @@ RssFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xitem ) newEntry->SetPostUrl ( xitem->FirstChildElement("link") ); newEntry->SetContent ( xitem->FirstChildElement("content:encoded") ); - if (cfg->verbose ) - printf("\t%s\n", newEntry->title.String()); - if ( lastDate == NULL || lastDate < newEntry->date ) lastDate = newEntry->date; - if ( withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) ) - entries.AddItem( newEntry ); + AddEntry( cfg, newEntry ); } void