A few months ago I started using a new service provided by carris to check how much time I have to wait for the bus.

Problem is, people at Carris never heard about webservices and rest apis, so I had to send an e-mail and wait for an automated reply with information about waiting times for the stop I was in.

So I wrote an Google App Engine App to wrap this operation and manage this process for me. All I have to do is provide the stop code and wait for the results.

You can check out the app here: http://lxbusinfo.appspot.com

The app is NOT beautiful  when seen on mobile devices, but it's at least usable. I'll get around to that as soon as I have some free time, but that is somewhat related with the second part of this post:

Since I developed a REST API to do this, you can also build your own app to check bus waiting times. Quite easily, in fact.

The process of obtaining bus information is of course asynchronous, since my app has to wait for an e-mail from carris.

All your App has to do is send a POST request with the stopcode parameter to http://lxbusinfo.appspot.com/api/newBusRequest You'll receive a reply like this one:

newBusRequest Form data: stopcode:10503

[
    {
        "requestid": "d71175fc592e4557b76d04f836dae30ef7afcb1d",
        "statuscode": 1
    }
]

This way, you'll receive a requestid you can use to poll the server at http://lxbusinfo.appspot.com/api/updateBusRequest using a GET request. This API call receives a requestid as parameter. Please wait at least 5 seconds between update requests. Here's an example of a GET request on updateBusRequest:

updateBusRequest?requestid=d71175fc592e4557b76d04f836dae30ef7afcb1d

[
    {
        "message": "",
        "payload": [
            {
                "dest": "PORTAS BENFICA",
                "eta_minutes": 4,
                "pt_timestamp": "21:09",
                "last_modified": "2010-10-01T20:04:41.481256",
                "busnr": 758
            },
            {
                "dest": "PR. REAL",
                "eta_minutes": 12,
                "pt_timestamp": "21:17",
                "last_modified": "2010-10-01T20:04:41.556630",
                "busnr": 790
            }
        ],
        "statuscode": 0
    }
]

As you can see, all replys are json encoded so you can parse them easily with JavaScript.

There are other replies and error codes, leave a comment if you want to implement something and I'll send you a nicer specification.

I'll open the source and setup a github repository as soon as I can get around to shape things up a bit.

I want to make this open source not only because I want to share the source but also because probably carris will do something to block my app, but if the source is open anyone can install the app elsewhere and setup a new bus information server. Problem is I don't want to share the source with Carris. :) Any thoughts on this? Lets hear it in the comments.



comments powered by Disqus