tidying up some stuff
This commit is contained in:
parent
f239a62572
commit
f052517741
12
lib/fx.js
12
lib/fx.js
@ -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
@ -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 () {
|
||||
|
@ -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='
|
||||
}
|
||||
];
|
||||
|
||||
|
44
lib/train.js
44
lib/train.js
@ -47,7 +47,7 @@ module.exports = {
|
||||
logger.debug(ts);
|
||||
//GLOBAL.lastcheck = now;
|
||||
logger.debug(ts.sta);
|
||||
// logger.debug(toSeconds(ts.sta));
|
||||
// logger.debug(toSeconds(ts.sta));
|
||||
|
||||
output.sta = ts.sta;
|
||||
output.eta = ts.eta;
|
||||
@ -60,26 +60,25 @@ module.exports = {
|
||||
|
||||
}
|
||||
},
|
||||
getTrainTimes: function(req, res) {
|
||||
// console.log(req);
|
||||
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';
|
||||
const url = '/all/' + req.query.from + '/to/' + req.query.to + '/10?accessToken=215b99fe-b237-4a01-aadc-cf315d6756d8';
|
||||
|
||||
Query(function (a, b) {
|
||||
Query(function (a, b) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(a));
|
||||
}, res, 'huxley.apphb.com', url);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
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));
|
||||
let trainFrom, trainTo, trainToken, url;
|
||||
if (req.query.hasOwnProperty('from') && req.query.hasOwnProperty('from')) {
|
||||
@ -97,21 +96,20 @@ module.exports = {
|
||||
Query(function (a, b) {
|
||||
|
||||
const output = {};
|
||||
logger.log('a', a);
|
||||
const ts = a.departures[0].service;
|
||||
if ( ts !== null)
|
||||
{
|
||||
// console.log(ts);
|
||||
if (ts !== null) {
|
||||
// console.log(ts);
|
||||
//GLOBAL.lastcheck = now;
|
||||
logger.debug(ts.sta, ts.std);
|
||||
// logger.debug(toSeconds(ts.sta));
|
||||
// logger.debug(toSeconds(ts.sta));
|
||||
|
||||
output.sta = (ts.sta !== null) ? ts.sta : ts.std;
|
||||
output.eta = (ts.eta !== null ? ts.eta : ts.etd);
|
||||
|
||||
// trainCache.last.glqdbe = toSeconds(ts.sta);
|
||||
// console.log(ts);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
logger.warn('*** NO SERVICE');
|
||||
output.sta = 'No Service';
|
||||
output.eta = 'No Service';
|
||||
@ -126,18 +124,18 @@ 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;
|
||||
Query(function (a, b) {
|
||||
|
||||
if (a !== null && a.message === null) {
|
||||
data = a;
|
||||
}
|
||||
if (a !== null && a.message === null) {
|
||||
data = a;
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(data));
|
||||
}, res, 'huxley.apphb.com', '/service/' + routeID + '?accessToken=215b99fe-b237-4a01-aadc-cf315d6756d8');
|
||||
@ -150,7 +148,7 @@ function toSeconds(inval) {
|
||||
console.log('inval', typeof inval);
|
||||
if (typeof inval === 'string') {
|
||||
const a = inval.split(':');
|
||||
return ((parseInt(a[0]) * (60 * 60)) + (parseInt(a[1]) * 60));
|
||||
return ((parseInt(a[0]) * (60 * 60)) + (parseInt(a[1]) * 60));
|
||||
}
|
||||
|
||||
return '';
|
||||
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user