tidying up some stuff

This commit is contained in:
Martin Donnelly 2017-04-02 23:42:24 +01:00
parent f239a62572
commit f052517741
6 changed files with 34 additions and 35 deletions

View File

@ -3,8 +3,8 @@ let fxCache = {};
exports.doFx = function (req,res) { exports.doFx = function (req,res) {
console.log('FX request'); console.log('FX request');
function fxQuery(callback, r) { function fxQuery(callback, r) {
var req = r; let req = r;
var options = { let options = {
host: 'openexchangerates.org', host: 'openexchangerates.org',
// port: 80, // port: 80,
path: '/api/latest.json?app_id=0eb932cee3bc40259f824d4b4c96c7d2', path: '/api/latest.json?app_id=0eb932cee3bc40259f824d4b4c96c7d2',
@ -17,7 +17,7 @@ exports.doFx = function (req,res) {
}; };
http.request(options).on('response', function (response) { http.request(options).on('response', function (response) {
var data = ''; let data = '';
response.on("data", function (chunk) { response.on("data", function (chunk) {
data += chunk; data += chunk;
}); });
@ -31,12 +31,12 @@ exports.doFx = function (req,res) {
}).end(); }).end();
} }
var now = new Date(); let now = new Date();
if (now - GLOBAL.lastcheck > (60000 * 14)) { if (now - GLOBAL.fxLastCheck > (60000 * 14)) {
fxQuery(function (a, b) { fxQuery(function (a, b) {
console.log(a); console.log(a);
fxCache = a; fxCache = a;
GLOBAL.lastcheck = now; GLOBAL.fxLastCheck = now;
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(fxCache)); res.end(JSON.stringify(fxCache));
}, res); }, res);

File diff suppressed because one or more lines are too long

View File

@ -17,7 +17,7 @@ const weather = require('./today/weather');
const trains = require('./today/trains'); const trains = require('./today/trains');
const history = require('./today/history'); const history = require('./today/history');
const mdMailer = require('./today/mailer'); const mdMailer = require('./today/mailer');
const mdFitbit = require('./today/fitbit'); // const mdFitbit = require('./today/fitbit');
const todayFTSE = require('./today/todayftse'); const todayFTSE = require('./today/todayftse');
const quotes = require('./today/quotes'); const quotes = require('./today/quotes');
//var db_name = 'silvrgit'; //var db_name = 'silvrgit';
@ -389,14 +389,14 @@ module.exports = {
console.error(e); console.error(e);
}); });
mdFitbit.getYesterdayFitbit() /*mdFitbit.getYesterdayFitbit()
.then((d) => { .then((d) => {
todayCache.data.fitbit = d; todayCache.data.fitbit = d;
}) })
.catch((e) => { .catch((e) => {
'use strict'; 'use strict';
console.error(e); console.error(e);
}); });*/
todayCache.date = breakDay(); todayCache.date = breakDay();
}, broadcast: function () { }, broadcast: function () {

View File

@ -11,8 +11,8 @@ const trainList = [
url: 'http://www.journeycheck.com/scotrail/route?from=DBE&to=GLQ&action=search&savedRoute=' url: 'http://www.journeycheck.com/scotrail/route?from=DBE&to=GLQ&action=search&savedRoute='
}, },
{ {
id: 'dbehym', id: 'glqhym',
url: 'http://www.journeycheck.com/scotrail/route?from=DBE&to=HYM&action=search&savedRoute=' url: 'http://www.journeycheck.com/scotrail/route?from=GLQ&to=HYM&action=search&savedRoute='
} }
]; ];

View File

@ -60,11 +60,10 @@ module.exports = {
} }
}, },
getTrainTimes: function(req, res) { getTrainTimes: function (req, res) {
// console.log(req); // console.log(req);
logger.info('getTrainTimes: ' + JSON.stringify(req.query)); logger.info('getTrainTimes: ' + JSON.stringify(req.query));
if (req.query.hasOwnProperty('from') && req.query.hasOwnProperty('from')) if (req.query.hasOwnProperty('from') && req.query.hasOwnProperty('from')) {
{
const url = '/all/' + req.query.from + '/to/' + req.query.to + '/10?accessToken=215b99fe-b237-4a01-aadc-cf315d6756d8'; const url = '/all/' + req.query.from + '/to/' + req.query.to + '/10?accessToken=215b99fe-b237-4a01-aadc-cf315d6756d8';
@ -73,13 +72,13 @@ module.exports = {
res.end(JSON.stringify(a)); res.end(JSON.stringify(a));
}, res, 'huxley.apphb.com', url); }, res, 'huxley.apphb.com', url);
} }
else{ else {
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({})); res.end(JSON.stringify({}));
} }
}, },
getNextTrainTimes: function(req, res) { getNextTrainTimes: function (req, res) {
logger.info('getNextTrainTimes: ' + JSON.stringify(req.query)); logger.info('getNextTrainTimes: ' + JSON.stringify(req.query));
let trainFrom, trainTo, trainToken, url; let trainFrom, trainTo, trainToken, url;
if (req.query.hasOwnProperty('from') && req.query.hasOwnProperty('from')) { if (req.query.hasOwnProperty('from') && req.query.hasOwnProperty('from')) {
@ -97,9 +96,9 @@ module.exports = {
Query(function (a, b) { Query(function (a, b) {
const output = {}; const output = {};
logger.log('a', a);
const ts = a.departures[0].service; const ts = a.departures[0].service;
if ( ts !== null) if (ts !== null) {
{
// console.log(ts); // console.log(ts);
//GLOBAL.lastcheck = now; //GLOBAL.lastcheck = now;
logger.debug(ts.sta, ts.std); logger.debug(ts.sta, ts.std);
@ -110,8 +109,7 @@ module.exports = {
// trainCache.last.glqdbe = toSeconds(ts.sta); // trainCache.last.glqdbe = toSeconds(ts.sta);
// console.log(ts); // console.log(ts);
} else } else {
{
logger.warn('*** NO SERVICE'); logger.warn('*** NO SERVICE');
output.sta = 'No Service'; output.sta = 'No Service';
output.eta = 'No Service'; output.eta = 'No Service';
@ -126,10 +124,10 @@ module.exports = {
} }
} }
}, getRoute: function(req, res) { }, getRoute: function (req, res) {
logger.info('getRoute: ' + JSON.stringify(req.query)); logger.info('getRoute: ' + JSON.stringify(req.query));
let routeID; let routeID;
const data = {}; let data = {};
if (req.query.hasOwnProperty('route')) { if (req.query.hasOwnProperty('route')) {
routeID = req.query.route; routeID = req.query.route;
@ -177,7 +175,7 @@ function Query(callback, r, host, path) {
response.on('end', function () { response.on('end', function () {
callback(JSON.parse(data), r); callback(JSON.parse(data), r);
}); });
response.on('error', function(e) { response.on('error', function (e) {
console.error(e); console.error(e);
}); });
}).end(); }).end();

View File

@ -46,6 +46,7 @@ const polys = require('./lib/poly.js');
const logger = require('log4js').getLogger(); const logger = require('log4js').getLogger();
const app = express(); const app = express();
GLOBAL.lastcheck = 0; GLOBAL.lastcheck = 0;
GLOBAL.fxLastCheck = 0;
let btcCache = {}, fxCache = {}, trainCache = {}; let btcCache = {}, fxCache = {}, trainCache = {};
const port = process.env.PORT || 9000; const port = process.env.PORT || 9000;