Skip to content

Commit 76ee35b

Browse files
committed
better response object style
1 parent a67282a commit 76ee35b

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

bvg.js

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
this.title = "Welcome to bvg webservice!";
1+
this.title = "Welcome to the inofficial bvg webservice!";
22
this.name = "bvg api module";
33
this.version = "0.0.1";
44
this.endpoint = "http://bvg-api.herokuapp.com";
@@ -8,6 +8,7 @@ var util = require('util'),
88
jjw = require('jjw');
99

1010
// you can pass an object -- will return an object with the results matching these keys
11+
/*
1112
var scrapers = {
1213
stations: function($) {
1314
var arr = []
@@ -17,6 +18,7 @@ var scrapers = {
1718
return arr;
1819
}
1920
};
21+
*/
2022

2123
exports.stations = function(options, callback){
2224
//http://mobil.bvg.de/IstAbfahrtzeiten/index/mobil?input=Stromstr.+%28Berlin%29
@@ -44,26 +46,34 @@ exports.stations = function(options, callback){
4446
});
4547
return arr;
4648
},
47-
departures: function($) {
49+
stations: function($) {
50+
/*
4851
var obj = {};
4952
obj.results = [];
5053
obj.status = "";
54+
*/
55+
var stations = [];
5156
$('.ivu_result_box').each(function(){
52-
if($(this).attr('id')=='ivuStreckeninfos') {
53-
obj.status = $.trim($(this).text());
54-
} else {
57+
if($(this).attr('id')!='ivuStreckeninfos') {
5558
$(this).find('.ivu_table').each(function(){
59+
var station = {};
60+
stations.push(station);
61+
station.id = $(this).find('thead tr th').text().match(/Mast:[\s]*(\w*)/)[1];
62+
station.departures = [];
5663
$(this).find('tbody tr').each(function(){
5764
var departure = {};
58-
departure.time = $.trim($(this).find('.ivu_table_c_dep').text());
65+
departure.time = $(this).find('.ivu_table_c_dep').text().replace(/\s/g, "");
5966
departure.line = $.trim($(this).find('.ivu_table_c_line').text());
6067
departure.direction = $.trim($(this).find('.catlink').text());
61-
obj.results.push(departure);
68+
station.departures.push(departure);
6269
});
70+
6371
});
72+
} else {
73+
//obj.status = $.trim($(this).text());
6474
}
6575
});
66-
return obj;
76+
return stations;
6777
}
6878
};
6979

@@ -84,15 +94,4 @@ exports.stations.schema = {
8494
type: 'string',
8595
optional: false
8696
}
87-
}
88-
89-
exports.departures = function(options, callback){
90-
callback(null, options.input);
91-
};
92-
exports.departures.description = "this is the echo method, it echos back your msg";
93-
exports.departures.schema = {
94-
input: {
95-
type: 'string',
96-
optional: false
97-
}
98-
};
97+
}

0 commit comments

Comments
 (0)