Importing Weather into Ignition

Hey all,

So I’m trying to import weather into ignition and from what I’ve see out there, the best way to go about doing this is using an XML.

the code I have been referencing has been provided by another user Weather script but I have pasted my script below that has been customized to my tag paths.

import system
import xml.dom.minidom

# Get Zip Code
zip = "85001"

url = "*&dayf=5" % zip
	response =
	# Put it in the dom
	dom = xml.dom.minidom.parseString(response)
	for node in dom.getElementsByTagName("loc"):
		system.tag.write("City State", node.getElementsByTagName("dnam")[0].firstChild.nodeValue)
	# Get the tag for current conditions
	for node in dom.getElementsByTagName("cc"):
		system.tag.write("Temp", node.getElementsByTagName("tmp")[0].firstChild.nodeValue)
		humid = node.getElementsByTagName("hmid")[0].firstChild.nodeValue + " %"
		system.tag.write("Humidity", humid)
		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.write("[Client]Weather/Current/Wind", windInfo)
		system.tag.write("[Client]Weather/Current/Date", node.getElementsByTagName("lsup")[0].firstChild.nodeValue)
		system.tag.write("[Client]Weather/Current/Icon", node.getElementsByTagName("icon")[0].firstChild.nodeValue)
		system.tag.write("[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.write("[Client]Weather/Day %d/Day" % day, node.getAttribute("t"))
				system.tag.write("[Client]Weather/Day %d/Low" % day, node.getElementsByTagName("low")[0].firstChild.nodeValue)
				system.tag.write("[Client]Weather/Day %d/High" % day, node.getElementsByTagName("hi")[0].firstChild.nodeValue)
			for partNode in node.getElementsByTagName("part"):
					if partNode.getAttribute("p") == "d":
						if day > 0:
							system.tag.write("[Client]Weather/Day %d/Icon" % day, partNode.getElementsByTagName("icon")[0].firstChild.nodeValue)
							system.tag.write("[Client]Weather/Day %d/Condition" % day, partNode.getElementsByTagName("t")[0].firstChild.nodeValue)
			day = day + 1
	system.tag.write("[Client]Weather/Live", 1)
	del response
	del dom
	print "Weather Update Successful!"
	system.tag.write("[Client]Weather/Live", 0)
	print "Weather Update Failed!"

I have tried this using yahoo weather but from what I have read the xml decoder no longer works for that site.

There is an error in the url line “int argument required” that I cant get past as well

Really all I care about is the temperature but for learning purposes I’d like to see if I can get the other stuff to work. Anyone have any experience with this stuff.

I have used openwweathermap for years. JSON is much easier to bring in than XML

lat = 45
lon = -114
appid = "put key here"

url = ""%locals()
_results = = url)
results = system.util.jsonDecode(_results)
print _results
if "name" in results:
	print "Name: " + str(results["name"])
print "Forecast: " + str(results["weather"][0]["main"])
print "Description: " + str(results["weather"][0]["description"]).title()
print "Temperature: " + str(results["main"]["temp"] - 273.15) + " C"
print "Temperature Low: " + str(results["main"]["temp_min"] - 273.15) + " C"
print "Temperature High: " + str(results["main"]["temp_max"] - 273.15) + " C"
print "Pressure: " + str(results["main"]["pressure"]) + " kPa"
print "Humidity: " + str(results["main"]["humidity"])