silvrgit/lib/train.min.js
martind2000 3e1087fd70 init
2016-03-08 21:52:21 +00:00

3 lines
1.5 KiB
JavaScript

function toSeconds(e){var t=e.split(":");return 3600*parseInt(t[0])+60*parseInt(t[1])}function Query(e,t,o,n){console.log(n);var a={host:o,path:n,headers:{}};try{http.request(a).on("response",function(o){var n="";o.on("data",function(e){n+=e}),o.on("end",function(){e(JSON.parse(n),t)})}).end()}catch(s){console.log(s)}}var http=require("http"),trainCache={last:{},data:{}};module.exports={dbe_glq:function(e,t){console.log("DBE:GLQ request");var o=new Date,n=3600*o.getHours()+60*o.getMinutes();console.log("Now Seconds: "+n),(null==trainCache.last.dbeglq||n!=trainCache.last.dbeglq)&&Query(function(e){var o=e.departures[0].service,n={};console.log(o),console.log(o.sta),n.sta=o.sta,n.eta=o.eta,trainCache.data.dbeglq=n,t.setHeader("Content-Type","application/json"),t.end(JSON.stringify(trainCache.data.dbeglq))},t,"huxley.apphb.com","/next/dbe/to/glq/1?accessToken=215b99fe-b237-4a01-aadc-cf315d6756d8")},glq_dbe:function(e,t){console.log("GLQ:DBE request");var o=new Date,n=3600*o.getHours()+60*o.getMinutes();console.log("Now Seconds: "+n),(null==trainCache.last.glqdbe||n!=trainCache.last.dbeglq)&&Query(function(e){var o=e.departures[0].service,n={};console.log(o),console.log(o.sta),console.log(toSeconds(o.sta)),n.sta=o.sta,n.eta=o.eta,trainCache.data.glqdbe=n,t.setHeader("Content-Type","application/json"),t.end(JSON.stringify(trainCache.data.glqdbe))},t,"huxley.apphb.com","/next/glq/to/dbe/1?accessToken=215b99fe-b237-4a01-aadc-cf315d6756d8")}};
//# sourceMappingURL=train.min.js.map