# Weather without regex

**URL:** <https://forum.inductiveautomation.com/t/weather-without-regex/4827>\
**Category:** Ignition\
**Created:** [July 16, 2012, 8:03pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827 "2012-07-16T20:03:30Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomt](https://avatars.discourse-cdn.com/v4/letter/t/90ced4/32.png) [@tomt](https://forum.inductiveautomation.com/u/tomt)\
**Post date:** [July 16, 2012, 8:03pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/1 "2012-07-16T20:03:30Z")

</div>

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.

```auto
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:  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/72276a07544ed76dedb45c871b47fabf2cb8f2b5.png)

---

<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:** [July 17, 2012, 5:11pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/2 "2012-07-17T17:11:06Z")

</div>

Nice, I like it! ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

---

<div class="post-metadata">

**Author:** ![tailfire](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tailfire](https://forum.inductiveautomation.com/u/tailfire)\
**Post date:** [July 18, 2012, 1:00am UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/3 "2012-07-18T01:00:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 18, 2012, 9:15am UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/4 "2012-07-18T09:15:55Z")

</div>

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! 🙂

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [July 18, 2012, 7:02pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/5 "2012-07-18T19:02:03Z")

</div>

[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?

---

<div class="post-metadata">

**Author:** ![tailfire](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tailfire](https://forum.inductiveautomation.com/u/tailfire)\
**Post date:** [July 18, 2012, 9:23pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/6 "2012-07-18T21:23:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tailfire](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tailfire](https://forum.inductiveautomation.com/u/tailfire)\
**Post date:** [July 18, 2012, 10:53pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/7 "2012-07-18T22:53:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tailfire](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tailfire](https://forum.inductiveautomation.com/u/tailfire)\
**Post date:** [July 19, 2012, 2:00am UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/8 "2012-07-19T02:00:14Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 19, 2012, 10:21am UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/9 "2012-07-19T10:21:00Z")

</div>

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](http://forecast.weather.gov/MapClick.php?lat=41.83962&lon=-84.33316939999997&unit=0&lg=english&FcstType=dwml).

---

<div class="post-metadata">

**Author:** ![jsham](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jsham](https://forum.inductiveautomation.com/u/jsham)\
**Post date:** [July 22, 2012, 3:48pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/10 "2012-07-22T15:48:12Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![halleys5](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/halleys5/32/3507_2.png) [@halleys5](https://forum.inductiveautomation.com/u/halleys5)\
**Post date:** [May 7, 2013, 4:12pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/11 "2013-05-07T16:12:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Macy77](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/macy77/32/11263_2.png) [@Macy77](https://forum.inductiveautomation.com/u/Macy77)\
**Post date:** [June 5, 2013, 5:02pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/12 "2013-06-05T17:02:45Z")

</div>

Thanks tomt, great script!

---

<div class="post-metadata">

**Author:** ![jcjeppesen](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jcjeppesen](https://forum.inductiveautomation.com/u/jcjeppesen)\
**Post date:** [July 2, 2013, 1:07pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/13 "2013-07-02T13:07:07Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [July 2, 2013, 5:24pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/14 "2013-07-02T17:24:56Z")

</div>

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

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

```auto
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"))
```

---

<div class="post-metadata">

**Author:** ![jcjeppesen](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jcjeppesen](https://forum.inductiveautomation.com/u/jcjeppesen)\
**Post date:** [July 2, 2013, 6:06pm UTC](https://forum.inductiveautomation.com/t/weather-without-regex/4827/15 "2013-07-02T18:06:55Z")

</div>

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