See also
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 (Programming Assignment 3 – Parsing HTML Web Pages).
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.
When the program starts, it shows the current conditions, immediate forecast and a quick five day forecast in a table.
If you later want to see an updated forecast and current conditions, click on the Reload Forecast button.
If you want to see the forecast and current conditions for a different location, click on the “Change Forecast Location” button. Here, I enter the zip code for the other campus of Kansas State University.
Clicking the OK button displays the forecast for the new location.
This screen is displayed, if a mistake is made while entering the zip code.
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.
File: wxWeather.py
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.
class WeatherPanel inherits wx.Panel and adds a wx.html.HtmlWindow to diplay HTML content. The HTML content comes from getWeather(), which gets data from from wuunderground and reformats it.
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 type: | a 3-dimensional list of strings [[[] .. ] .. ] |
|---|
Returns the text data held in the table
Class to collect and report on the current weather conditions, which are spread out over multiple tables.
| Parameter: | data – a list of (variable, value) tuples. |
|---|
Collect current weather condition information from token data.
| Parameter: | 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.