[Tutor] parsing response from SOAPpy request

2007-09-01 Thread Sean Cronin
I'm using SOAPpy to access weather data from the NOAA National Digital
Forecast Database XML Web Service [1] and I've been having
trouble figuring out how to parse the data.

The response comes back as XML document but when I check it with
type(result) it shows the the response is a string.  Does anyone have any
suggestions on getting relevant data? I've attached a sample SOAP response
to this post.

Thanks,
-Sean

http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 

xsi:noNamespaceSchemaLocation="http://www.nws.noaa.gov/forecasts/xml/DWMLgen/schema/DWML.xsd";>
   
  
 NOAAs National Weather Service Forecast by 12 Hour 
period
 meteorological
 forecast
 2007-08-31T21:35:20Z
  
  
 
http://www.nws.noaa.gov/forecasts/xml/
 Meteorological Development Laboratory 
Product Generation Branch
 http://www.nws.noaa.gov/disclaimer.html
 http://www.weather.gov/
 http://www.weather.gov/images/xml_logo.gif
 
http://www.weather.gov/survey/nws-survey.php?code=xmlsoap
  
   
   
  
 point1
 
  
  
  k-p24h-n7-1
  2007-08-31T06:00:00-04:00
  2007-08-31T18:00:00-04:00
  2007-09-01T06:00:00-04:00
  2007-09-01T18:00:00-04:00
  2007-09-02T06:00:00-04:00
  2007-09-02T18:00:00-04:00
  2007-09-03T06:00:00-04:00
  2007-09-03T18:00:00-04:00
  2007-09-04T06:00:00-04:00
  2007-09-04T18:00:00-04:00
  2007-09-05T06:00:00-04:00
  2007-09-05T18:00:00-04:00
  2007-09-06T06:00:00-04:00
  2007-09-06T18:00:00-04:00
  
  
  k-p24h-n7-2
  2007-08-31T18:00:00-04:00
  2007-09-01T06:00:00-04:00
  2007-09-01T18:00:00-04:00
  2007-09-02T06:00:00-04:00
  2007-09-02T18:00:00-04:00
  2007-09-03T06:00:00-04:00
  2007-09-03T18:00:00-04:00
  2007-09-04T06:00:00-04:00
  2007-09-04T18:00:00-04:00
  2007-09-05T06:00:00-04:00
  2007-09-05T18:00:00-04:00
  2007-09-06T06:00:00-04:00
  2007-09-06T18:00:00-04:00
  2007-09-07T06:00:00-04:00
  
  
  k-p12h-n14-3
  2007-08-31T06:00:00-04:00
  2007-08-31T18:00:00-04:00
  2007-08-31T18:00:00-04:00
  2007-09-01T06:00:00-04:00
  2007-09-01T06:00:00-04:00
  2007-09-01T18:00:00-04:00
  2007-09-01T18:00:00-04:00
  2007-09-02T06:00:00-04:00
  2007-09-02T06:00:00-04:00
  2007-09-02T18:00:00-04:00
  2007-09-02T18:00:00-04:00
  2007-09-03T06:00:00-04:00
  2007-09-03T06:00:00-04:00
  2007-09-03T18:00:00-04:00
  2007-09-03T18:00:00-04:00
  2007-09-04T06:00:00-04:00
  2007-09-04T06:00:00-04:00
  2007-09-04T18:00:00-04:00
  2007-09-04T18:00:00-04:00
  2007-09-05T06:00:00-04:00
  2007-09-05T06:00:00-04:00
  2007-09-05T18:00:00-04:00
  2007-09-05T18:00:00-04:00
  2007-09-06T06:00:00-04:00
  2007-09-06T06:00:00-04:00
  2007-09-06T18:00:00-04:00
  2007-09-06T18:00:00-04:00
  2007-09-07T06:00:00-04:00
  
  
 
Daily Maximum Temperature
85
80
83
85
86
84
84
 
 
Daily Minimum Temperature
59
57
62
67
66
66

 
 
12 Hourly Probability of Precipitation
18
14
0
0
0
0
7
9
10
14
14
20
20

 
 
Weather Type, Coverage, and Intensity






















   
   
   
   


   
   
   
   


 
 
Conditions Icons
   
   
http://www.nws.noaa.gov/weather/images/fcicons/nfew.jpg
   
http://www.nws.noaa.gov/weather/images/fcicons/few.jpg
   

[Tutor] Best way to construct this

2007-09-01 Thread Sean Cronin[tutor]
Hi,

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
].childNodes[1]

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.

-Sean

[1] http://www.weather.gov/forecasts/xml/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Best way to construct this

2007-09-02 Thread Sean Cronin[tutor]
Hey,

Thanks Alan for the help on the classes.  This is my first time using them
(in case you couldn't tell :) ).  However, I can't understand why you want
to make a separate function called parse.  What I am trying to do by having
different functions in the class like maxtemp, and mintemp, is to allow my
self to be able to parse only for certain data,
instead of having one giant function that parses for everything. That
way I have the option of being able to selectively parse the data.
It also gives me the option as you said of being able to reparse the
data later if it became corrupted somehow.


Also, where should I put the value for the maxtempnode since you set them
equal to none in the pseudo code you sent.

>class Weather:
>def init(self, fname):
>self.filename = fname
>self.data = None
>self.maxtemp = None
>self.maxnode = None

Should I change the None to what their values should be, or should I do that
at some point later in the code?

Thanks,

-Sean
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor