Skip to content

Instantly share code, notes, and snippets.

@foysalit
Created September 10, 2016 20:48
Show Gist options
  • Save foysalit/fde303a4ae0c689102d13b9639089910 to your computer and use it in GitHub Desktop.
Save foysalit/fde303a4ae0c689102d13b9639089910 to your computer and use it in GitHub Desktop.
gtt bus time table parser with cheerio and meteor
import { HTTP } from 'meteor/http';
import { load as loadPage } from 'cheerio';
const url = `http://www.gtt.to.it/cms/percorari/arrivi`;
Meteor.methods({
getArrivals: function(stopNumber) {
let data = [];
let page = HTTP.call('GET', url, {params: {
palina: stopNumber,
realtime: true,
option: 'com_gtt',
bacino: 'U'
}});
let $ = loadPage(page.content);
$('.table-striped tbody > tr').each(function () {
let $col = $(this).find('td');
let bus = {
id: $col.eq(0).text().trim(),
destination: $col.eq(1).text().trim(),
arrivals: $col.eq(2).text().trim().split(' ')
};
data.push(bus);
});
console.log(data)
return data;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment