Created
September 10, 2016 20:48
-
-
Save foysalit/fde303a4ae0c689102d13b9639089910 to your computer and use it in GitHub Desktop.
gtt bus time table parser with cheerio and meteor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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