An overall discussion of the design of the wxWeather program along with the Python module requirements and a link to download the program is found in the previous section (Example of Parsing HTML Web Pages with Html5lib).
Here is a short description of how to use the wxWeather program along with screen shots from the program.
The initial forecast location (zip code) is hard coded to 67401 for Salina, Kansas, but it can easily be changed in the source code.
If you later want to see an updated forecast and current conditions, click on the Reload Forecast button.
Here is a little bit of documentation about the more important functions and classes from the wxWeather program. This documentation is auto-generated from the Python source code and doc strings contained in the source code.
Author: Tim Bower, Copyright 2009, Open Source Apache License – See non-docstring source code comments for license details.
HTML parser - extract the current conditions and 5-day forecast from www.wunderground.com and display it in a simple wxPython graphical window.
A component of Project 3 for Network Programming Class.
The main GUI class for wxWeather – no real reason why this code is at the panel level instead of the frame level with the panel being just one of the objects in the frame. I started with wxHTML, which does it this way.
Call back from clicking the close window (X) icon on the frame. Close the application by Destroying the object
Call back from Change Forecast Location button
Call back from Reload Forecast button
As the HTML is parsed, any tables get stored here. This just helps to orgaize and later retrieve the data.
New data to add to the current table cell. Items are stored in a list. Thus, a 2 dimensional HTML table is stored as a Python 3-dimensional list.
Return the table data formated as HTML. Returns a list of strings. This is debugging code - not used in the final program.
|Return type:||a 3-dimensional list of strings [[ .. ] .. ]|
Returns the text data held in the table
A generic table printer, depending on the data, it may or or may not get the job done, but could help with debugging. In most cases, you will want to use getTableData() and format the data per your needs.
A td end-tag (end of column)
A td start-tag (new column)
A tr end-tag (end of row)
A tr start-tag (new row)
Get the length of the table – useful to guess which table we are working with.
Boolean: Determine if table data holds a desired string
Transpose a table – rows and columns switch. This is probably the trickiest line of code used in this class. Without using the nested list comprehension, it would be much longer.
Class to collect and report on the current weather conditions, which are spread out over multiple tables.
Return current conditions data with HTML formatting.
A boolean to test to see if we are still looking for current condition data.
|Parameters:||data – a list of (variable, value) tuples.|
Collect current weather condition information from token data.
|Parameters:||zipcode – 5 digit zip code string (optional)|
Grab a page from wunderground and parse it, strip out a quick summary and return the summary with simple HTML formating.
If the current table is what we want, return it as HTML formated as we want it. This function will the first to be modified when wuWeather ever changes the format of the HTML.