Skip to content

Instantly share code, notes, and snippets.

@scripting
Created January 1, 2021 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scripting/b09d57587e428502cf1c77325e502d7b to your computer and use it in GitHub Desktop.
Save scripting/b09d57587e428502cf1c77325e502d7b to your computer and use it in GitHub Desktop.
{
"name": "testriver6lanes",
"version": "0.4.0",
"main": "test.js",
"dependencies" : {
"daveutils": "*",
"davesql": "*"
}
}
var myVersion = "0.4.0", myProductName = "testriver6lanes";
const fs = require ("fs");
const utils = require ("daveutils");
const request = require ("request");
const davesql = require ("davesql");
var config = {
};
function markFeedAsUpdated (feedrec, callback) {
feedrec.whenUpdated = new Date ();
if (feedrec.ctsubs !== undefined) { //1/1/21 by DW
delete feedrec.ctsubs;
}
davesql.runSqltext ("replace into feeds " + davesql.encodeValues (feedrec), callback);
}
function findLeastRecentlyUpdatedFeed (flFastLane, callback) {
var extraComparison = (flFastLane) ? "f.ctConsecutiveErrors < 2" : "f.ctConsecutiveErrors > 1";
var sqltext = "select f.*, count(s.listName) as ctsubs from feeds f left join subscriptions s on s.feedUrl = f.feedUrl group by f.feedUrl having ctsubs >= 1 and " + extraComparison + " order by f.whenUpdated asc limit 1;"
davesql.runSqltext (sqltext, function (err, result) {
if (result.length > 0) {
callback (result [0]);
}
});
}
function readConfig (callback) {
fs.readFile ("config.json", function (err, data) {
if (!err) {
var jstruct = JSON.parse (data);
for (var x in jstruct) {
config [x] = jstruct [x];
}
}
callback ();
});
}
function check () {
findLeastRecentlyUpdatedFeed (true, function (theFeed) {
console.log (theFeed.feedUrl + ", last updated " + utils.getFacebookTimeString (theFeed.whenUpdated));
markFeedAsUpdated (theFeed);
});
}
readConfig (function () {
console.log ("config == " + utils.jsonStringify (config));
davesql.start (config.database, function () {
setInterval (check, 250);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment