Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • kasalehlia/s0infodisplay
  • rohieb/s0infodisplay
  • larsan/s0infodisplay
  • marudor/s0infodisplay
  • thies/s0infodisplay
  • f10sh/s0infodisplay
6 results
Show changes
Commits on Source (1)
  • rohieb's avatar
    WIP: fix EFA api · c3cfdb96
    rohieb authored
    needs itdTime & itdDate, and can no longer parse stop names directly :-(
    c3cfdb96
......@@ -5,7 +5,10 @@ var httpreq = require('httpreq');
/// CONFIG
var CITY = 'Braunschweig';
var STOPS = ['Ludwigstraße','Hamburger Straße'];
var STOPS = [
{ id: 26000335, name: 'Ludwigstraße' },
{ id: 26000169, name: 'Hamburger Straße' }
];
var ENTRIES = 6;
/// VARS
......@@ -26,11 +29,19 @@ function pad(n, width, z) {
}
function fetchData(stop, cb) {
var url = "http://62.154.206.87/efaws2/default/XML_DM_REQUEST?sessionID=0&requestID=0&language=de&useRealtime=1&coordOutputFormat=WGS84[DD.ddddd]&locationServerActive=1&mode=direct&dmLineSelectionAll=1&depType=STOPEVENTS&useAllStops=1&command=null&type_dm=stop&name_dm="+CITY+' '+stop+"&mId=efa_rc2"
var d = new Date();
var itdTime = pad(d.getHours(),2) + pad(d.getMinutes(),2);
var itdDate = d.getFullYear() + pad(d.getMonth()+1,2) + pad(d.getDate(),2);
var url = 'https://efa155.efa.de/efaws2/default/XML_DM_REQUEST?outputFormat=JSON&language=de&useRealtime=1&coordOutputFormat=WGS84[DD.ddddd]&locationServerActive=1&mode=direct&dmLineSelectionAll=1&depType=STOPEVENTS&useAllStops=1&command=null&type_dm=stop&name_dm='+stop.id+'&itdTime='+itdTime+'&itdDate='+itdDate+'&mId=efa_www';
console.log('bus: url=' + url);
httpreq.get(url, {binary: true}, function (err, res) {
try {
cb(XML.parse(res.body));
if (err) {
throw new Error('httpreq: ' + err);
}
cb(JSON.parse(res.body));
} catch(e) {
console.log('bus: ' + e);
}
});
}
......@@ -74,7 +85,7 @@ function update(io, allStopsDoneCb) {
var ns = normalizeStop(stop);
getData(stop, ENTRIES, function (deps) {
try {
context[i] = {stop: stop, normalizedStop: ns, deps: deps};
context[i] = {stop: stop[1], normalizedStop: ns, deps: deps};
io.emit('bus.'+ns, Mustache.render(TEMPLATES.inner, context[i]));
if (done.indexOf(stop) === -1) {
done.push(stop);
......@@ -101,7 +112,7 @@ function update(io, allStopsDoneCb) {
}
function normalizeStop(stop) {
return stop.replace(/[^a-zA-Z0-9_]/g,'');
return stop.name.replace(/[^a-zA-Z0-9_]/g,'');
}
module.exports = function (io) {
......