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) {
console.log('FX request');
function fxQuery(callback, r) {
var req = r;
var options = {
let req = r;
let options = {
host: 'openexchangerates.org',
// port: 80,
path: '/api/latest.json?app_id=0eb932cee3bc40259f824d4b4c96c7d2',
@ -17,7 +17,7 @@ exports.doFx = function (req,res) {
};
http.request(options).on('response', function (response) {
var data = '';
let data = '';
response.on("data", function (chunk) {
data += chunk;
});
@ -31,12 +31,12 @@ exports.doFx = function (req,res) {
}).end();
}
var now = new Date();
if (now - GLOBAL.lastcheck > (60000 * 14)) {
let now = new Date();
if (now - GLOBAL.fxLastCheck > (60000 * 14)) {
fxQuery(function (a, b) {
console.log(a);
fxCache = a;
GLOBAL.lastcheck = now;
GLOBAL.fxLastCheck = now;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(fxCache));
}, 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 history = require('./today/history');
const mdMailer = require('./today/mailer');
const mdFitbit = require('./today/fitbit');
// const mdFitbit = require('./today/fitbit');
const todayFTSE = require('./today/todayftse');
const quotes = require('./today/quotes');
//var db_name = 'silvrgit';
@ -389,14 +389,14 @@ module.exports = {
console.error(e);
});
mdFitbit.getYesterdayFitbit()
/*mdFitbit.getYesterdayFitbit()
.then((d) => {
todayCache.data.fitbit = d;
})
.catch((e) => {
'use strict';
console.error(e);
});
});*/
todayCache.date = breakDay();
}, broadcast: function () {

View File

@ -11,8 +11,8 @@ const trainList = [
url: 'http://www.journeycheck.com/scotrail/route?from=DBE&to=GLQ&action=search&savedRoute='
},
{
id: 'dbehym',
url: 'http://www.journeycheck.com/scotrail/route?from=DBE&to=HYM&action=search&savedRoute='
id: 'glqhym',
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);
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';
@ -73,13 +72,13 @@ module.exports = {
res.end(JSON.stringify(a));
}, res, 'huxley.apphb.com', url);
}
else{
else {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({}));
}
},
getNextTrainTimes: function(req, res) {
getNextTrainTimes: function (req, res) {
logger.info('getNextTrainTimes: ' + JSON.stringify(req.query));
let trainFrom, trainTo, trainToken, url;
if (req.query.hasOwnProperty('from') && req.query.hasOwnProperty('from')) {
@ -97,9 +96,9 @@ module.exports = {
Query(function (a, b) {
const output = {};
logger.log('a', a);
const ts = a.departures[0].service;
if ( ts !== null)
{
if (ts !== null) {
// console.log(ts);
//GLOBAL.lastcheck = now;
logger.debug(ts.sta, ts.std);
@ -110,8 +109,7 @@ module.exports = {
// trainCache.last.glqdbe = toSeconds(ts.sta);
// console.log(ts);
} else
{
} else {
logger.warn('*** NO SERVICE');
output.sta = '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));
let routeID;
const data = {};
let data = {};
if (req.query.hasOwnProperty('route')) {
routeID = req.query.route;
@ -177,7 +175,7 @@ function Query(callback, r, host, path) {
response.on('end', function () {
callback(JSON.parse(data), r);
});
response.on('error', function(e) {
response.on('error', function (e) {
console.error(e);
});
}).end();

View File

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