Save 'LastDate' attribute to cache files

This commit is contained in:
Jaidyn Ann 2020-08-11 13:29:49 -05:00
parent 21ad59927f
commit 5cc00b8df3
3 changed files with 18 additions and 3 deletions

View File

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

View File

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

View File

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