Merge pull request #1 from smattie/update-interval

Add update intervals
This commit is contained in:
dogeystamp 2023-01-15 11:12:32 -05:00 committed by GitHub
commit cb4158424d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -14,6 +14,7 @@ You should have received a copy of the GNU General Public License along with thi
typedef struct {
const char *url;
const char *feedName;
const time_t update;
} linkStruct;
/* Example link:
@ -21,6 +22,8 @@ typedef struct {
.url = "https://example.com/rss/feed.rss",
// This will be used as the folder name for the feed.
.feedName = "examplefeed",
// The time in seconds between checks for updates.
.update = 3600,
},
*/
@ -28,6 +31,7 @@ static const linkStruct links[] = {
{
.url = "",
.feedName = "",
.update = 0,
},
};

View File

@ -13,6 +13,8 @@ You should have received a copy of the GNU General Public License along with thi
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <utime.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlreader.h>
@ -215,10 +217,20 @@ main(int argc, char *argv[])
outputStruct outputs[LEN(links)];
memset(outputs, 0, sizeof(outputs));
time_t timeNow = time(NULL);
for (i = 0; i < LEN(links); i++) {
struct stat feedDir;
if (links[0].url[0] == '\0')
logMsg(0, "No feeds, add them in config.def.h\n");
if (stat(links[i].feedName, &feedDir) == 0) {
time_t deltaTime = timeNow - feedDir.st_atim.tv_sec;
if (deltaTime < links[i].update)
continue;
}
logMsg(4, "Requesting %s\n", links[i].url);
createRequest(links[i].url, &outputs[i]);
}
@ -231,7 +243,17 @@ main(int argc, char *argv[])
logMsg(5, "Parsing %s\n", links[i].url);
if (outputs[i].buffer && outputs[i].buffer[0]) {
readDoc(outputs[i].buffer, links[i].feedName, itemAction);
if (readDoc(outputs[i].buffer, links[i].feedName, itemAction) == 0) {
struct stat feedDir;
if (stat(links[i].feedName, &feedDir) == 0) {
struct utimbuf update;
update.actime = timeNow;
update.modtime = feedDir.st_mtim.tv_sec;
utime(links[i].feedName, &update);
}
}
free(outputs[i].buffer);
}
}