Easy Weather Icons

Hey all,

I was playing around with the code in the manual to get the current weather conditions from the yahoo website and I came across a very easy way to add weather icons for the different conditions.
First I added a piece of code that would get a weather icon code from the same place that it gets the conditions and temperature:

iconcode = re.compile('.*?code="(.*?)"').match(subText).group(1)

Then I put wrote that code into a db tag:

system.tag.writeToTag("Gateway Tags/Weather Icon Code",iconcode)

Then I found this cool icon pack that matches up exactly with Yahoo’s weather codes (I’ll add it as an attachment)

Now you just have to run a script to put the code number from Yahoo into the path for the icons like so:

try: window = system.gui.getWindow('Main Window') weathericon = window.rootContainer.getComponent('WeatherCondition') condition = system.tag.getTagValue("Gateway Tags/Weather Icon Code") weathericon.path = "Weather/" + condition + ".png" except ValueError: pass

Bam! Easy weather icons.
weather_png.zip (1.03 MB)

I am a cadet fresh from training,
I have successfully used the script and it writes a number to the db tag.
I am having trouble with the expression for the icon code to actually change the icon path.
Any help would be cool. I really like this script…

Attached is a screenshot. Just in case that helps. I feel like I am not putting something in the right place…obviously…


I am thinking I do not need to create an expression for the icon path lol… It got real mad when I finally satisfied the syntax…


Maybe I need to use indirect tag binding?

No, you shouldn’t need any bindings on the picture component. The script should take care of changing the file path for you. A couple things I notice in the pictures you posted, the picture component name should be WeatherCondition, weathericon is just a object placeholder in the script to be able to assign the path to the actual WeatherCondition component. I run the script code in a client timer script like so:


This script gets the window object that you have the icon in, then gets the picture component (which is named WeatherCondition in my example) and then assigns the picture path to it.


You should also double check that you imported the condition pictures to the correct directory or change the directory structure in the script to match where you uploaded them to but it looks like you’re just hung up on how to run the script. Hopefully this helps you!

EDIT:

Also I noticed that your window name is ‘Welcome Page’, so the first line of the timer script should be:

window = system.gui.getWindow('Welcome Page')

so it gets the correct window object. FYI.

As always, there’s more than one way to skin this cat. We get our weather data from NOAA. We load the attached script in as app.weather and run the following expression, either bound to a tag or directly to the image path property on an image placeholder.

toStr(runscript("app.weather.noaa('KEMP')['icon_url_base']", 600000))
+ toStr(runscript("app.weather.noaa('KEMP')['icon_url_name']", 600000))

Actually, we don’t even do that anymore… we run the dictionary through a pair of transaction groups and write it to a single-row realtime database table and then just query from that. Keeps the internet traffic down a little for remote, low-bandwidth sites.

Nice thing about this method is you don’t need to download icons - this is done on the fly by linking direct to NOAA. Maybe bad internet etiquette to directly fetch images from someone else’s hosting… YMMV.
weather.py (2.18 KB)

I finally got it, I had to add (“Main Windows/Welcome Page”) to the client script finally giving it the path.
I am using the Nav/Teir project which categorizes the windows for us. Do believe it was that structure was throwing me off.
It is always rewarding when something finally works in Ignition… I like the icons.
Both methods depend on a web service, so both have their dependencies.
Thank you Duffanator for the help. With practice it does get easier…

Thanks again to all here on the forum.