Weather without regex

I was looking to get weather data without using regex. Turns out it is pretty easy. This is an almost copy/paste replacement for the weather script I have seen other places. This is also a good example to get started with pulling other XML feeds.

import xml.dom.minidom
#get the data
response = system.net.httpGet("http://xml.weather.yahoo.com/forecastrss?p=55012")

#put it in the dom
dom1 = xml.dom.minidom.parseString(response)

#get the tag for current conditions
for node in dom1.getElementsByTagName("yweather:condition"):
	#get the attributes, and write the tags
	system.tag.writeToTag("Weather/Condition",node.getAttribute("text"))
	system.tag.writeToTag("Weather/Code",node.getAttribute("code"))
	system.tag.writeToTag("Weather/Temp",node.getAttribute("temp"))

#the first forecast in the file is for today (there are two in this feed)
day = "Today"
#loop through the forecasts
for node in dom1.getElementsByTagName("yweather:forecast"):
	#get the attributes and write the appropriate tags
	system.tag.writeToTag("Weather/"+day+"/date",node.getAttribute("date"))
	system.tag.writeToTag("Weather/"+day+"/low",node.getAttribute("low"))
	system.tag.writeToTag("Weather/"+day+"/high",node.getAttribute("high"))
	system.tag.writeToTag("Weather/"+day+"/condition",node.getAttribute("text"))
	#the second time we loop through, write the data to the tomorrow folder
	day = "Tomorrow"

Need a tag structure like this:

Nice, I like it! :thumb_left:

I sure like this too. have you guys come up with a better radar feed? im using accuweather thats an image from url.
I also noticed accuweather “sells” a tailored xml service for a monthly fee. would any of you care to post any screenhots
from your weather feed?

The xml module must be a Jython 2.5 thing. It wasn’t available in Jython 2.1 (pre-Ignotion 7.4). Otherwise, I’d certainly have gone that route! :slight_smile:

[quote=“tailfire”]I sure like this too. have you guys come up with a better radar feed? im using accuweather thats an image from url.
I also noticed accuweather “sells” a tailored xml service for a monthly fee. would any of you care to post any screenhots
from your weather feed?[/quote]

Any reason you couldn’t use NOAA’s data services?

probably foreknowledge of the service . can you post a link?

wow ! i searched for it and they (noaa) offer wsdl/xml services!!! very cool. doez not appear that the example in this post
is using it. can you post examples if you are using the noaa service?

The xml feed in this post appears way easier to use than the wsdl from noaa
Is there a chance that the IA guys can post some examples/how-to’s on actually implementing the
suds for wsdl services. I have a lighting controls server getting ready to arrive at my plant for the cutler hammer lighting controls that I am adding to our scada.
I purchased this thing in hopes of working through the details. It looks to me like practicing with the noaa service might be good wsdl practice.
Any help and or documentation here by the IA guys would be appreciated…

Here’s an example link for getting xml from the NOAA site.

http://forecast.weather.gov/MapClick.php?lat=41.83962&lon=-84.33316939999997&unit=0&lg=english&FcstType=dwml.

We use NOAA for our weather… you can see how we do it in this thread… http://www.inductiveautomation.com/forum/viewtopic.php?f=50&t=6732

Now that the xml tools are available in jython, we may re-write to get rid of some of the java code though.

Thanks tomt! I was trying to do this from scratch for hours, saw your post, cut, paste, and I’m nearly done!
Appreciate you posting it.

Thanks tomt, great script!

Anyone notice that Yahoo changed the forcast to 5 day. now the code in the script returns 4 days out not next day.
Thought this may work…

for node in dom1.getElementsByTagName(“yweather:forecast”)[1]:

But not…

If you just want today’s forecast, then replace the entire for statement:

node = dom1.getElementsByTagName(“yweather:forecast”)[0]

day = "Today"
#get todays forecast
node = dom1.getElementsByTagName("yweather:forecast")[0]
#get the attributes and write the appropriate tags
system.tag.writeToTag("Weather/"+day+"/date",node.getAttribute("date"))
system.tag.writeToTag("Weather/"+day+"/low",node.getAttribute("low"))
system.tag.writeToTag("Weather/"+day+"/high",node.getAttribute("high"))
system.tag.writeToTag("Weather/"+day+"/condition",node.getAttribute("text"))

Was posting to fix code for tomorrows forcast…
tried node= no change.
Thanks