Merge pull request #1 from smattie/update-interval
Add update intervals
This commit is contained in:
commit
cb4158424d
@ -14,6 +14,7 @@ You should have received a copy of the GNU General Public License along with thi
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
const char *url;
|
const char *url;
|
||||||
const char *feedName;
|
const char *feedName;
|
||||||
|
const time_t update;
|
||||||
} linkStruct;
|
} linkStruct;
|
||||||
|
|
||||||
/* Example link:
|
/* Example link:
|
||||||
@ -21,6 +22,8 @@ typedef struct {
|
|||||||
.url = "https://example.com/rss/feed.rss",
|
.url = "https://example.com/rss/feed.rss",
|
||||||
// This will be used as the folder name for the feed.
|
// This will be used as the folder name for the feed.
|
||||||
.feedName = "examplefeed",
|
.feedName = "examplefeed",
|
||||||
|
// The time in seconds between checks for updates.
|
||||||
|
.update = 3600,
|
||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -28,6 +31,7 @@ static const linkStruct links[] = {
|
|||||||
{
|
{
|
||||||
.url = "",
|
.url = "",
|
||||||
.feedName = "",
|
.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 <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <utime.h>
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <libxml/xmlreader.h>
|
#include <libxml/xmlreader.h>
|
||||||
@ -215,10 +217,20 @@ main(int argc, char *argv[])
|
|||||||
outputStruct outputs[LEN(links)];
|
outputStruct outputs[LEN(links)];
|
||||||
memset(outputs, 0, sizeof(outputs));
|
memset(outputs, 0, sizeof(outputs));
|
||||||
|
|
||||||
|
time_t timeNow = time(NULL);
|
||||||
|
|
||||||
for (i = 0; i < LEN(links); i++) {
|
for (i = 0; i < LEN(links); i++) {
|
||||||
|
struct stat feedDir;
|
||||||
|
|
||||||
if (links[0].url[0] == '\0')
|
if (links[0].url[0] == '\0')
|
||||||
logMsg(0, "No feeds, add them in config.def.h\n");
|
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);
|
logMsg(4, "Requesting %s\n", links[i].url);
|
||||||
createRequest(links[i].url, &outputs[i]);
|
createRequest(links[i].url, &outputs[i]);
|
||||||
}
|
}
|
||||||
@ -231,7 +243,17 @@ main(int argc, char *argv[])
|
|||||||
logMsg(5, "Parsing %s\n", links[i].url);
|
logMsg(5, "Parsing %s\n", links[i].url);
|
||||||
|
|
||||||
if (outputs[i].buffer && outputs[i].buffer[0]) {
|
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);
|
free(outputs[i].buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user