[Tutor] Best way to construct this

Sean Cronin[tutor] seancron+pythontutor at gmail.com
Sun Sep 2 05:32:11 CEST 2007


I'm trying to create a desktop weather program using the weather.gov SOAP
XML feed[1] and (after I get the insides all sorted out) Tkinter.  However,
this is my first major program and I was wondering if anyone could offer me
some guidance in the construction of it.

I have settled on using SOAPpy for the SOAP interface and pyXML to parse the
resulting XML, but I am having trouble figuring out what the most efficient
way of parsing the XML and arranging my program.

Right now I have two modules named libndfdsoap and weatherpy.  Module
libndfdsoap contains one function that gets the XML and saves it to a file
named weather.xml.  Module weatherpy contains some constants and a class for
parsing the XML with different functions for find different data types.

I am using xml.dom.minidom and using childNodes to narrow down to the values
that I need and then storing that in a dictionary. Here's a snippet of
the code:

class ByDayXMLParse:
    """Contains functions for parsing the NDFD XML"""
    def __init__(self, path_to_xml_file):
    global data, maxtempdata, maxtempnode
    data = minidom.parse(path_to_xml_file)
    #Dictionary in which the max temps are going to be stored in the format
    #{1: day1temp, 2: day2temp, ...}
    maxtempdata = {}
    #Less typing for me :)
    maxtempnode = data.childNodes[0].childNodes[3].childNodes[9

    def maxTemp(self, path_to_xml_file):
        x = 3
        y = 1
    while x < 16:
        maxtempdata[y] = maxtempnode.childNodes[x].childNodes[0].data
        x, y = x + 2, y + 1

I've tried putting the XML parsing code in libndfdsoap but by doing so I
couldn't access the resulting data.  I can't help but feel like I'm missing
something that will make my life a whole lot easier.

Any help would be greatly appreciated.


[1] http://www.weather.gov/forecasts/xml/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070901/377b6f56/attachment.htm 

More information about the Tutor mailing list