From 5cc00b8df30f1a19c6c9b34262e9c9414ece63e0 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Tue, 11 Aug 2020 13:29:49 -0500 Subject: [PATCH] Save 'LastDate' attribute to cache files --- src/AtomFeed.cpp | 7 +++++++ src/Feed.cpp | 7 ++++--- src/RssFeed.cpp | 7 +++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/AtomFeed.cpp b/src/AtomFeed.cpp index 17fb613..6a57a20 100644 --- a/src/AtomFeed.cpp +++ b/src/AtomFeed.cpp @@ -27,6 +27,10 @@ AtomFeed::Parse ( Config* cfg ) 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) ); } void @@ -76,6 +80,9 @@ 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 ) + lastDate = newEntry->date; + if ( xcontent ) { xcontent->Accept( &xprinter ); newEntry->SetContent( xprinter.CStr() ); diff --git a/src/Feed.cpp b/src/Feed.cpp index 711d1c5..aadd15a 100644 --- a/src/Feed.cpp +++ b/src/Feed.cpp @@ -14,7 +14,8 @@ Feed::Feed ( BString path, Config* cfg ) filePath = GetCachePath( path, cfg ); } -Feed::Feed ( ) { +Feed::Feed ( ) +{ title = BString(""); description = BString(""); homeUrl = BString(""); @@ -52,7 +53,7 @@ Feed::FetchRemoteFeed ( BString givenPath, Config* cfg ) filename.Append(splitName); BFile* cacheFile = new BFile( filename, B_READ_WRITE | B_CREATE_FILE ); - cacheFile->ReadAttr( "FeedSum", B_STRING_TYPE, 0, + cacheFile->ReadAttr( "LastHash", B_STRING_TYPE, 0, oldHash, 41 ); if ( cfg->verbose ) @@ -60,7 +61,7 @@ Feed::FetchRemoteFeed ( BString givenPath, Config* cfg ) webFetch( givenUrl, cacheFile, newHash ); - cacheFile->WriteAttr( "FeedSum", B_STRING_TYPE, 0, + cacheFile->WriteAttr( "LastHash", B_STRING_TYPE, 0, newHash->String(), newHash->CountChars() ); if ( *(newHash) == BString(oldHash) ) diff --git a/src/RssFeed.cpp b/src/RssFeed.cpp index 5399e79..1e0b297 100644 --- a/src/RssFeed.cpp +++ b/src/RssFeed.cpp @@ -27,6 +27,10 @@ RssFeed::Parse ( Config* cfg ) 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) ); } // ------------------------------------- @@ -58,6 +62,9 @@ RssFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xitem ) 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 ); }