# Weather script

**URL:** <https://forum.inductiveautomation.com/t/weather-script/12304>\
**Category:** Ignition\
**Created:** [October 28, 2016, 8:21pm UTC](https://forum.inductiveautomation.com/t/weather-script/12304 "2016-10-28T20:21:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [October 28, 2016, 8:21pm UTC](https://forum.inductiveautomation.com/t/weather-script/12304/1 "2016-10-28T20:21:51Z")

</div>

Ok maybe this has been asked but I couldn’t find it.  
So I have been running the weather script for awhile and then it stopped working. I believe this was due to yahoo changing. But i am wondering what is a new way to get the weather?

Thanks

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 31, 2016, 3:59pm UTC](https://forum.inductiveautomation.com/t/weather-script/12304/2 "2016-10-31T15:59:51Z")

</div>

Weather Underground has an API that’s free to use for low volumes of request (it just requires registration) and it can return XML data just as Yahoo Weather used to.

[wunderground.com/weather/api/](https://www.wunderground.com/weather/api/)

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [October 31, 2016, 4:06pm UTC](https://forum.inductiveautomation.com/t/weather-script/12304/3 "2016-10-31T16:06:06Z")

</div>

Here’s one that I modified to get weather information from [www.weather.com](http://www.weather.com). You can see if that works for you.

[code]def update():  
import system  
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.write("[Client]Weather/City State", node.getElementsByTagName("dnam")[0].firstChild.nodeValue)
	
	# Get the tag for current conditions
	for node in dom.getElementsByTagName("cc"):
		system.tag.write("[Client]Weather/Current/Temp", node.getElementsByTagName("tmp")[0].firstChild.nodeValue)
		humid = node.getElementsByTagName("hmid")[0].firstChild.nodeValue + " %"
		system.tag.write("[Client]Weather/Current/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!"
except:
	system.tag.write("[Client]Weather/Live", 0)
	print "Weather Update Failed!"[/code]
```

---

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [October 31, 2016, 7:41pm UTC](https://forum.inductiveautomation.com/t/weather-script/12304/4 "2016-10-31T19:41:07Z")

</div>

[quote=“Duffanator”]Here’s one that I modified to get weather information from [weather.com](http://www.weather.com). You can see if that works for you.

[code]def update():  
import system  
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.write("[Client]Weather/City State", node.getElementsByTagName("dnam")[0].firstChild.nodeValue)
	
	# Get the tag for current conditions
	for node in dom.getElementsByTagName("cc"):
		system.tag.write("[Client]Weather/Current/Temp", node.getElementsByTagName("tmp")[0].firstChild.nodeValue)
		humid = node.getElementsByTagName("hmid")[0].firstChild.nodeValue + " %"
		system.tag.write("[Client]Weather/Current/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!"
except:
	system.tag.write("[Client]Weather/Live", 0)
	print "Weather Update Failed!"[/code][/quote]

```

Sorry I am a little slow on the uptake. What would the UDT structure look like?

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [November 1, 2016, 11:56am UTC](https://forum.inductiveautomation.com/t/weather-script/12304/5 "2016-11-01T11:56:05Z")

</div>

They should be client tags and be structured like this:

[attachment=0]WeatherTagStructure.jpg.jpg[/attachment]

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [December 13, 2018, 10:39pm UTC](https://forum.inductiveautomation.com/t/weather-script/12304/6 "2018-12-13T22:39:41Z")

</div>

Hi all!

I know this is not a recent thread, but I’m trying to find details for the API to [wxdata.weather.com](http://wxdata.weather.com) and can’t seem to find it via Google.  
Anyone got a link to a page where I can find out what the various tags are the API provides?

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![hamlinjr](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hamlinjr/32/8228_2.png) [@hamlinjr](https://forum.inductiveautomation.com/u/hamlinjr)\
**Post date:** [December 13, 2018, 11:03pm UTC](https://forum.inductiveautomation.com/t/weather-script/12304/7 "2018-12-13T23:03:19Z")

</div>

Well this; [(weather channel API)](https://www.programmableweb.com/api/weather-channel), points you to this; [(weather underground API)](https://www.wunderground.com/weather/api/?ref=twc), which says the free public API has been shutdown.

IBM owns both companies, and offers the data for a fee if you’re interested…

---

<div class="post-metadata">

**Author:** ![rjmah](https://avatars.discourse-cdn.com/v4/letter/r/b9e5f3/32.png) [@rjmah](https://forum.inductiveautomation.com/u/rjmah)\
**Post date:** [October 31, 2019, 12:56am UTC](https://forum.inductiveautomation.com/t/weather-script/12304/8 "2019-10-31T00:56:53Z")

</div>

[https://openweathermap.org/current](https://openweathermap.org/current) has a free API service then pay for more data and functions.
