diff --git a/config.def.h b/config.def.h index 2deb2c8..06e1823 100644 --- a/config.def.h +++ b/config.def.h @@ -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, }, }; diff --git a/minrss.c b/minrss.c index e531181..b7a220e 100644 --- a/minrss.c +++ b/minrss.c @@ -13,6 +13,8 @@ You should have received a copy of the GNU General Public License along with thi #include #include #include +#include +#include #include #include #include @@ -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); } }