Tuesday, October 17, 2006

Rants of a Snake Charmer - II

Traffic App


This is a small application that displays the realtime traffic data to the user. I was inspired by a nifty little sample program in the BREW SDK that allowed the San Diego county traffic data available on CalTrans website to be viewed in a specialized client on the handset. Of course, the BREW SDK being as complicated as it is, this solution is easier on the eyes.

Things You Need

The PyS60 is an essential subset of Python. All the must-have features of Python are packaged with it. What this also means is most platform independent features of Python can be simply added to PyS60. The task of porting the programs that rely on these features becomes quite straightforward. For the Traffic App, you will need the following modules from your local Python installation:


Once you have copied these modules to the libs folder (or resource folder on S60 3rd ed.), we are ready to put the Traffic App in place.

Network Data

The data needed for this particular application is requested from the folowing URL:

This data is the following format:

<TABLE><CAPTION>[Highway Name]--[Date]--[Time]</CAPTION>
<TR><TD class=head>LOCATION</TD><TD class=head>SPEED<BR></TD></TR>
<TR><TD>[Exit 1]</TD><TD class=green>58 mph</TD></TR>
<TR><TD>[Exit 2]</TD><TD class=green>59 mph</TD></TR>
<TR><TD>[Exit 3]</TD><TD class=yellow>37 mph</TD></TR>
<TR><TD>[Exit 4]</TD><TD class=red>18 mph</TD></TR>
<TR><TD>[Exit 5]</TD><TD class=menuitem>no data</TD></TR><TR>
What we need for a bare minimum Traffic App is an HTTP client and a parser that understands the predefined format mentioned above. Since Python and thus PyS60 readily provide the HTTP parser and HTML parser framework, all we need is a simple UI, a traffic parser, and we are done.


The following files are in the codebase:

  • (Module to parse the response from the traffic data server)
  • (The application)
  • speeds.mbm (Icons)

The code can be found here. The snapshots are on top of the blog.


I hope you enjoyed this little application. I would recommend that you take the following points home:

  • Talking in HTTP with PyS60
  • HTML parsing with PyS60
  • Using icons in a ListBox


Blogger โชติ ธรีะวิท said...

This is such very big problem with people,thanks for sharing this.

12:50 AM  

Post a Comment

Links to this post:

Create a Link

<< Home