commit 44631099d3085b24b3499586e68dc3e9568fc3d5
parent 7b83fc06751d2c6cef9eafc3cc5d4ed2309cc926
Author: MTRNord <mtrnord1@gmail.com>
Date: Sat, 10 Sep 2016 19:57:22 +0200
Add some asyncing and parallizing
Diffstat:
7 files changed, 40 insertions(+), 18 deletions(-)
diff --git a/handlers/getNodes.js b/handlers/getNodes.js
@@ -20,7 +20,7 @@ var slack = require('./slack.js');
*/
module.exports = {
saveNodes: function () {
- request.get('http://cdn.rawgit.com/MTRNord/gluon-web-remote/develop/configs/communities.json', function (err, res, body) {
+ request.get('https://cdn.rawgit.com/MTRNord/gluon-web-remote/5d0c3a2c49b79d2971b8b3cc24398d45833ad1c6/configs/communities.json', function (err, res, body) {
if (!err && res.statusCode == 200) {
/**
diff --git a/handlers/pushbullet.js b/handlers/pushbullet.js
@@ -17,6 +17,9 @@ module.exports = {
*/
pushbulletSend: function (door_status){
var token = process.env.pushbullet_api
+ if ((token == undefinded) || (token == "")) {
+ console.log("No token defined")
+ }
curl.request({ url: 'https://api.pushbullet.com/v2/pushes', method: 'POST', headers: { "Access-Token": token, "Content-Type": 'application/json' }, data: '{"channel_tag": "space-door", "body":"'+ door_status + '","title":"Door Status","type":"note"}'}, function (err, stdout, meta) {
if (err){
/**
diff --git a/handlers/telegram.js b/handlers/telegram.js
@@ -1,5 +1,7 @@
-//TOKEN 165809140:AAEEpJP4hgcEsf6ry1Vd6Lp0_8rfRrXFB3A
-var token = '165809140:AAEEpJP4hgcEsf6ry1Vd6Lp0_8rfRrXFB3A';
+var token = process.env.telegram_api
+if ((token == undefinded) || (token == "")) {
+ console.log("No token defined")
+}
var TelegramBot = require('node-telegram-bot-api');
var jsonfile = require('jsonfile')
var getNodes = require('./getNodes.js');
diff --git a/handlers/tmp/communities.json b/handlers/tmp/communities.json
@@ -3,7 +3,7 @@
"FFKI": {
"ccode": "FFKI",
"name": "Freifunk Kiel",
- "nodesURL": "http://map.ffki.de/nodes.json",
+ "nodesURL": "http://mesh.freifunk.in-kiel.de/data/nodes.json",
"v6": "fda1:384a:74de:",
"v6mask": "/48",
"v4": "10.116.0.0",
@@ -23,7 +23,7 @@
"FFNORD": {
"ccode": "FFNORD",
"name": "Freifunk Nord",
- "nodesURL": "http://mesh.ffnord.net/data/nodes.json",
+ "nodesURL": "https://mesh.nord.freifunk.net/data/nodes.json",
"v6": "2a03:2267:4e6f:7264:",
"v6mask": "/64",
"v4": "10.187.0.0",
@@ -193,7 +193,7 @@
"FFHH": {
"ccode": "FFHH",
"name": "Freifunk Hamburg",
- "nodesURL": "https://map.hamburg.freifunk.net/nodes.json",
+ "nodesURL": "https://map.hamburg.freifunk.net/nodelist.json",
"v6": "2a03:2267::",
"v6mask": "/48",
"v4": "10.112.0.0",
diff --git a/handlers/tmp/community.json b/handlers/tmp/community.json
@@ -1 +0,0 @@
-751
-\ No newline at end of file
diff --git a/main.js b/main.js
@@ -12,6 +12,7 @@ var schedule = require('node-schedule');
var argv = require('yargs').argv;
var params_config = require("./configs/ircServer.json");
var autoupdate = params_config["autoupdate"];
+var async = require("async");
//LOAD MODULES DOWN HERE
require('./helper/heroku.js');
@@ -25,11 +26,6 @@ var telegram = require('./handlers/telegram.js');
var SIGINT = "SIGINT";
var door_status2 = "1";
-//Startup
-irc.ircPreload();
-getNodes.saveNodes()
-telegram.start()
-
/**
* Get door-status from the Web
@@ -114,9 +110,6 @@ process.on(SIGINT, function () {
process.exit();
}).setMaxListeners(0);
-//Activate IRC-Bot Command Handler
-irc.ircBotCommands();
-
/**
* Update - Pull last master from Github
*
@@ -151,5 +144,29 @@ var j = schedule.scheduleJob('59 3 * * *', function(){
}
});
-//Run Mainfunction 20seconds after script start
-setTimeout(function() { GetData(); }, 20000);
+//Startup
+async.whilst(
+ function (callback) {
+ // callback has to be called by `uploadImage` when it's done
+ irc.ircPreload(callback)
+ },
+ function (callback) {
+ getNodes.saveNodes(callback)
+ },
+ function (callback) {
+ telegram.start(callback)
+ },
+ function (callback) {
+ //Activate IRC-Bot Command Handler
+ irc.ircBotCommands(callback)
+ },
+ function (callback) {
+ //Run Mainfunction 20seconds after script start
+ setTimeout(function() { GetData(callback); }, 20000)
+ },
+ function(err, n) {
+ if (err) {
+ console.log(err)
+ }
+ }
+);
+\ No newline at end of file
diff --git a/package.json b/package.json
@@ -20,6 +20,7 @@
"notification"
],
"dependencies": {
+ "async": "^2.0.1",
"botanio": "0.0.6",
"curlrequest": "^0.5.4",
"ent": "git+https://github.com/substack/node-ent.git",