Skip to content

Instantly share code, notes, and snippets.

@notheotherben
Created January 30, 2015 08:41
Show Gist options
  • Save notheotherben/d4caf959fb7824a9855c to your computer and use it in GitHub Desktop.
Save notheotherben/d4caf959fb7824a9855c to your computer and use it in GitHub Desktop.
Eskom Load Shedding Cron Job for Kong
var request = require('superagent'),
fs = require('fs'),
_ = require('lodash');
var config = require('./config.json');
var status = require('./status.json');
_.each(config.areas, function(area) {
request.get('/api/' + area.code + '/' + var2).end(function(err, data) {
if(err) throw err;
var schedule = [{
starts: new Date(),
ends: new Date()
}];
gotSchedule(schedule);
});
function gotSchedule(schedule) {
request.post(config.kong).data({
area: area.name,
level:
schedule: schedule
}).end(function(err) {
if(err) throw new Error("Couldn't push schedule to devices");
console.log("Pushed schedule for %s", area.name);
})
}
});
{
"name": "eskom2kong",
"version": "1.0.0",
"dependencies": {
"lodash": "*",
"superagent": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment