feature-image_GTTwebsite

Download and parse data to be displayed

In version 1.0 of PocketGTT all information are obtained from internet. The online site of GTT is available under multiple addresses:

For a desktop usage I recommend the 5T website, but it has some javascript additional function that made it difficult to decode the information written on the page. Because, the goal here is to download a page from the internet on the phone, read its content pack the information needed in some variables and then these variable will be displayed somewhere on the phone screen. So for PocketGTT I have used the mobile version of the 5T site. It has a compact layout and a request can be easily done. The page to load is the following:
http://www.5t.torino.it/pda/it/arrivi.jsp
If you know the number of the stop (for example 471, a stop in Castello square), the page to load will be:
http://www.5t.torino.it/pda/it/arrivi.jsp?n=471
The resulting page will look like this:
GTT mobile website
While from the page code we can identify some area where to look for information:

 Arrivi in fermata

Fermata richiesta: 471 – CASTELLO
in piazza Castello

So this is the first code snippet to look for in the programm, while the line are described with a ul tag

  • Linea 13

    17:26 * 17:40 * 17:52 * 18:02

  • Linea 15

    17:46 * 17:49 […]

  • […]

So in case the tag ul with class=passaggi exists, we look for tag span with class=n. and in each span, we search if another tag span, but with class=rt (realtime) exists.
In whis way we have decoded the information available on website, with realtime data. There are other option that we shoudl consider and manage with a list of if statements:

  • No passages in the next 2h
  • Stop number doesn’t exists
  • Multiple stop respond to the requested text

Regarding the last point, it is possible with the same link to look for a stop based on name instead of code. Code is unique, so no doubt, but there are multiple stops with the same name (think at the same stop but for the 2 different directions). As example open the folllowing link:
http://www.5t.torino.it/pda/it/arrivi.jsp?n=castello
In a similar way as described above, we should recognize the page and the list of possible stops.

Leave a Reply

Your email address will not be published. Required fields are marked *