Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Train_stations query produces empty array #3

Open
MOAMIndustries opened this issue Nov 8, 2014 · 10 comments
Open

Train_stations query produces empty array #3

MOAMIndustries opened this issue Nov 8, 2014 · 10 comments

Comments

@MOAMIndustries
Copy link

Forgive me if I am doing something wrong, this is just something I am playing around with however from the best of my knowledge something is broken with the train times response
the URL: http://api.perthtransit.com/1/train_stations/perth
Provides:
{"response":{"lat":"-31.9510907808","lng":"115.859925408","name":"Perth","times":[],"compact":false,"identifier":"perth"}}

Whilst I was expecting:
{
"response": {
"identifier": "perth",
"compact": false,
"lat": "-31.9510908",
"lng": "115.8599254",
"name": "Perth",
"times": [{
"cars": 4,
"line": "Midland",
"on_time": true,
"pattern": null,
"platform": 7,
"status": "On Time",
"time": "19:00"
}, {
"cars": 2,
"line": "Fremantle",
"on_time": true,
"pattern": "K",
"platform": 5,
"status": "On Time",
"time": "19:02"
}, {
"cars": 4,
"line": "Armadale",
"on_time": true,
"pattern": "C",
"platform": 6,
"status": "On Time",
"time": "19:02"
}]
}
}

Is the empty times array a result of some broken interface with transperth or is my query wrong?

@Sutto
Copy link
Owner

Sutto commented Nov 9, 2014

Hey there - it looks like they changed the page we're scraping so it'd need to be fixed. I'll take a look when I get a chance if you'd like?

@MOAMIndustries
Copy link
Author

That would be great, thanks. It is a bit beyond my skill set to try and fork it and fix it.

@andrewgoz
Copy link

I think the changes required are to transperth-api/lib/transperth_client.rb :

Line 23, change to:

URL_SCHEME = "/Timetables/Live-Train-Times?stationname=%s"

Line 73, change to:

container = doc.css('table.table tbody tr')

Line 84, change to:

status = tds[4]

Line 126, change to (there's only one select on the entire page):

doc.css('select option').map { |r| r[:value] }

I can't install ruby 1.9 otherwise I'd test it myself. Note that the %s in the URL_SCHEME needs to resolve to something like "perth+underground+Stn". It is case-insensitive, but needs the trailing "+stn".

@lukerollans
Copy link

Big +1 for getting this working again. I'm going to give the above changes suggested by @andrewgoz shortly, and if they don't work, try fixing it myself

@Sutto
Copy link
Owner

Sutto commented Mar 11, 2015

Hey guys - thanks for the work and sorry I let it slip again. I've pushed the updated version (there were a few other changes) - and it's working again it appears (see http://api.perthtransit.com/1/train_stations/armadale) - If all works for you guys, I'll update and make sure you get credit in the readme @andrewgoz - thanks!

@lukerollans
Copy link

Wicked, thanks @Sutto

@andrewgoz
Copy link

I knew this just needed a gentle poke :-)

I can confirm the changes work - just published my updated Pebble app with new train information! Thanks muchly @Sutto.

@andrewgoz
Copy link

It seems to be missing the first train?

@Sutto
Copy link
Owner

Sutto commented Mar 19, 2015

Hey guys,

This was a bug to do with the page change - they moved the headers into a thead element (Yah!) so the scraper had incorrect data.

I've fixed this (and made a few other general tweaks) and am deploying it now with the changes.

@andrewgoz
Copy link

Seems good now :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants