Created
January 1, 2021 16:29
-
-
Save scripting/b09d57587e428502cf1c77325e502d7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "testriver6lanes", | |
"version": "0.4.0", | |
"main": "test.js", | |
"dependencies" : { | |
"daveutils": "*", | |
"davesql": "*" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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