Added update intervals
This commit is contained in:
parent
dadddb79d9
commit
b7232e4401
@ -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,
|
||||
},
|
||||
};
|
||||
|
||||
|
24
minrss.c
24
minrss.c
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user