Google

Tuesday, October 17, 2006

Rants of a Snake Charmer - II


Traffic App


Background


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:

  1. formatter.py
  2. htmlentitydefs.py
  3. HTMLLIB.PY
  4. markupbase.py
  5. SGMLLIB.PY

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:

<HTML>
<HEAD>....
</HEAD>
<BODY>...
<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>
</TABLE>
</BODY>
</HTML>
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.

Code

The following files are in the codebase:

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

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

Summary

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

3 Comments:

Blogger thanida said...

This comment has been removed by the author.

12:50 AM  
Blogger thanida said...

This is exactly what I was looking for. Thanks for sharing this great blog
isc888

11:24 PM  
Blogger lnwslot789 said...

ดูหนังออนไลน์ ระดับ Premium ง่ายๆ ได้ที่ Doonung1234 ฟรี ระดับ 4K HD หลากหลายเรื่อง กับเรื่อง โฮมสเตย์ Homestay (2018)

6:31 PM  

Post a Comment

<< Home