Created
January 30, 2015 08:41
-
-
Save notheotherben/d4caf959fb7824a9855c to your computer and use it in GitHub Desktop.
Eskom Load Shedding Cron Job for Kong
This file contains 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 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); | |
}) | |
} | |
}); | |
This file contains 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": "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