Google Weather Code Replacement

Hey all,

I’m sure some of you have recently run into the problem of Google shutting down their weather XML feed. If you have used the setup that Inductive Automation has in their 7.6 demo you know what I’m talking about!

I have updated the code to work with weather.com’s XML feed. Everything will be the same except the icon tags are numbers, so you have to edit the templates to reflect the icon number code instead of the google web path. I’m still working through what all of the numbers are but when I get them all done I’ll post it here. Thanks, Google! :imp:

[code]def update():
import system, app
import xml.dom.minidom

# Get Zip Code
zip = system.tag.read("[Client]Weather/Zip").value

url = "http://wxdata.weather.com/wxdata/weather/local/%d?cc=*&dayf=5" % zip
 
try:
	response = system.net.httpGet(url)
	
	# Put it in the dom
	dom = xml.dom.minidom.parseString(response)
	
	for node in dom.getElementsByTagName("loc"):
		system.tag.writeToTag("[Client]Weather/City State", node.getElementsByTagName("dnam")[0].firstChild.nodeValue)
	
	# Get the tag for current conditions
	for node in dom.getElementsByTagName("cc"):
		system.tag.writeToTag("[Client]Weather/Current/Temp", node.getElementsByTagName("tmp")[0].firstChild.nodeValue)
	for node in dom.getElementsByTagName("cc"):
		humid = node.getElementsByTagName("hmid")[0].firstChild.nodeValue + " %"
		system.tag.writeToTag("[Client]Weather/Current/Humidity", humid)
	for node in dom.getElementsByTagName("cc"):
		for subNode in node.getElementsByTagName("wind"):
			speed = subNode.getElementsByTagName("s")[0].firstChild.nodeValue
			direction = subNode.getElementsByTagName("t")[0].firstChild.nodeValue
			windInfo = direction + " at " + speed + " mph"
			system.tag.writeToTag("[Client]Weather/Current/Wind", windInfo)
	for node in dom.getElementsByTagName("cc"):
		system.tag.writeToTag("[Client]Weather/Current/Date", node.getElementsByTagName("lsup")[0].firstChild.nodeValue)
	for node in dom.getElementsByTagName("cc"):
		system.tag.writeToTag("[Client]Weather/Current/Icon", node.getElementsByTagName("icon")[0].firstChild.nodeValue)
	for node in dom.getElementsByTagName("cc"):
		system.tag.writeToTag("[Client]Weather/Current/Condition", node.getElementsByTagName("t")[0].firstChild.nodeValue)

	
	# Get the tags for the next 2 days forecast
	day = 0
	for node in dom.getElementsByTagName("dayf"):
		for node in dom.getElementsByTagName("day"):
			if day > 0:
				system.tag.writeToTag("[Client]Weather/Day %d/Day" % day, node.getAttribute("t"))
			day = day + 1
	
	day = 0
	for node in dom.getElementsByTagName("dayf"):
		for node in dom.getElementsByTagName("day"):
			if day > 0:
				system.tag.writeToTag("[Client]Weather/Day %d/Low" % day, node.getElementsByTagName("low")[0].firstChild.nodeValue)
			day = day + 1
	
	day = 0
	for node in dom.getElementsByTagName("dayf"):
		for node in dom.getElementsByTagName("day"):
			if day > 0:
				system.tag.writeToTag("[Client]Weather/Day %d/High" % day, node.getElementsByTagName("hi")[0].firstChild.nodeValue)
			day = day + 1

	day = 0
	for node in dom.getElementsByTagName("dayf"):
		for partNode in dom.getElementsByTagName("part"):
			if partNode.getAttribute("p") == "d":
				if day > 0:
					system.tag.writeToTag("[Client]Weather/Day %d/Icon" % day, partNode.getElementsByTagName("icon")[0].firstChild.nodeValue)
				day = day + 1
				
	day = 0
	for node in dom.getElementsByTagName("dayf"):
		for dayNode in node.getElementsByTagName("day"):	
			if dayNode.getAttribute("d") != "0":
				for partNode in dayNode.getElementsByTagName("part"):
					if partNode.getAttribute("p") == "d":
						if day > 0:
							system.tag.writeToTag("[Client]Weather/Day %d/Condition" % day, partNode.getElementsByTagName("t")[0].firstChild.nodeValue)
						day = day + 1
			else:
				day = day + 1
				
	system.tag.write("[Client]Weather/Live", 1)
except:
	system.tag.write("[Client]Weather/Live", 0)[/code]