Weather Underground Plugin

Questions and comments specific to a particular plugin should go here.
Post Reply
User avatar
kgschlosser
Site Admin
Posts: 4652
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weather Underground Plugin

Post by kgschlosser » Wed Apr 19, 2017 4:26 am

ok here is the latest and greatest


Added a help tab that gives the layout of the plugins data class
Added polling this can be accessed form the plugin config dialog.
Added 2 new actions StartPoll and StopPoll the poll has to already exist for either one of these to work.

I have removed the triggering of an event when an action is called. this is due to the events taking place from the polling

The polling thread window will inform you if you are going to go over 10 requests per minute.
the settings are all pretty self explanatory.

There is one glitch I am still trying to hammer out. the polling idea is so it will trigger an event if something has changed.. while this does work for a string return a jason or ElementTree object. it is not functioning for the plugins data class. if you use the data class it will always trigger an event. I will figure out what the issue is.

but here it is
Attachments
WeatherUnderground.1.4b.egplugin
(25.51 KiB) Downloaded 103 times
If you like the work I have been doing then feel free to Image

User avatar
yokel22
Experienced User
Posts: 265
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Weather Underground Plugin

Post by yokel22 » Wed Apr 19, 2017 6:13 am

Sounds awesome. I'll try to get around to really playing with this now that polling events are going. Also, maybe change the placeholder for the api key. I kinda found that confusing how you had the api key url there too. Maybe you were thinking to direct people there to get a key. You could add a link in the config if that was the case. Sorry, just nitpicking.

User avatar
kgschlosser
Site Admin
Posts: 4652
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weather Underground Plugin

Post by kgschlosser » Wed Apr 19, 2017 4:54 pm

no worries. I was trying to direct people to where to get it. But i guess i can just add it as a link to the config dialog.

I am going to add an option to the polling to either trigger an event every time the poll takes place. or to trigger an event only of the data has changed. This will be in the next release along with the fixed isdirty on the data class
If you like the work I have been doing then feel free to Image

loveleejohn
Experienced User
Posts: 129
Joined: Thu Dec 10, 2015 12:09 am

Re: Weather Underground Plugin

Post by loveleejohn » Mon May 01, 2017 4:32 pm

It's great to see this one's still going. I ran away to try to grasp the basics of python and I actually have a few scripts that work in my tree now! lol. That said, for some reason I can't figure out how to do the basic task of printing the current weather conditions in the log with this plugin. It's not your fault kg! I think you've done a great job, I'm just really really slow with Eventghost. :oops: I'll head over to the coding corner and see if someone can help me get my python certificate so I can try this out!

User avatar
kgschlosser
Site Admin
Posts: 4652
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weather Underground Plugin

Post by kgschlosser » Mon May 01, 2017 7:31 pm

lol

no worries

it's very simple actually.. all the actions work this way

so make your action...
then do a dump result to log action.

easy cheezy

the whole thing is set up in such a way that if you do a print eg.result it will automatically convert that data class into a formatted text output.. so if you wanted to display is as an OSD instead you would wrap the result in str() this is what print does internally but if you wanted to make use of the text elsewhere that is the mechanism to do it

Code: Select all

str(eg.result)
Now if you wanted say a specific date for a forecast. you would make the forecast action then create a python script and enter the code below. but changing the date to the date you want

Code: Select all

print eg.result.May01
and if you happen to just want the Nighttime forecast

Code: Select all

print eg.result.May01.Night

So as another example. if you wanted to dynamically get the forecast for tomorrow.. meaning that when tomorrow comes then tomorrow will be the day after.. if you get my meaning.. this will always give the forecast for the day after the current day.

remember to make your forecast action then add this to a PythonScript below it.

Code: Select all

import datetime

date = datetime.datetime.now()
date += datetime.timedelta(days=1)
forecast_date = date .strftime('%b%d').lower()
print eg.result[forecast_date]
the line

Code: Select all

 date += datetime.timedelta(days=1) 
if you change the days= to 2 it will give the forecast for the day after tomorrow. and so on and so forth. remember to not exceed the number of days the forecast is for. so a 4 day forcast the most you could set the days= to is 3 and for a 10 day the most you could set it to is 9. This is because today is one of those days in the forecast. and if you wanted to always print the forecast for today then you would simply remove that line.

today is always the day the Script is run on. and tomorrow is always the day after the script is run on.
If you like the work I have been doing then feel free to Image

loveleejohn
Experienced User
Posts: 129
Joined: Thu Dec 10, 2015 12:09 am

Re: Weather Underground Plugin

Post by loveleejohn » Mon May 01, 2017 7:48 pm

Ok thanks kg! I'm sure you know it'll probably take me a week just to get this to work so I'll let you know how I fare when all the dust has settled. Lol.

User avatar
kgschlosser
Site Admin
Posts: 4652
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weather Underground Plugin

Post by kgschlosser » Mon May 01, 2017 7:51 pm

The data in the forecast can be access in 2 ways. either as an object attribute or as a dictionary. if accessing it as a dictionary then the key always has to be lowercase.

Code: Select all

eg.result.May01
is the same as doing

Code: Select all

eg.result['may01']
I set it up this way to make it easier to dynamically grab data. because doing the following is easier to understand and read

Code: Select all

dynamic_date = 'may01'
forecast = eg.result[dynamic_date]
then having to do this

Code: Select all

dynamic_date = 'may01'
forecast = getattr(eg.result, dynamic_date.title())
If you like the work I have been doing then feel free to Image

loveleejohn
Experienced User
Posts: 129
Joined: Thu Dec 10, 2015 12:09 am

Re: Weather Underground Plugin

Post by loveleejohn » Mon May 01, 2017 7:56 pm

Someone needs to hide this program from me! Sadly it's not working. I am seeing a lot of red in the log when I copy and paste your code into a new python action that I place right after the original weather underground action within the macro. The main issue is saying something about str having no attribute May01. :(

User avatar
kgschlosser
Site Admin
Posts: 4652
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weather Underground Plugin

Post by kgschlosser » Mon May 01, 2017 7:57 pm

What you have to remember also is that if you ask for something like a temperature. and you use the object method of grabbing the data

example for current conditions temperature

Code: Select all

eg.result.High
it will automatically return the proper unit of measure. so if you told it to use imperial in the action then it will return Fahrenheit

but if you access it using the dictionary method then you will have to use the unit of measure. which changes depending on what action you use. so use the Help thing to show the tree exploded view of the actual data to know what the keys are

Code: Select all

eg.result['high']['fahrenheit']
this was done so if you needed the data from the opposite of what you selected in the action you can still access it.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4652
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weather Underground Plugin

Post by kgschlosser » Mon May 01, 2017 8:00 pm

go into the action and click on the other tab (can't remember what i named it.) in there is should show you the data. and the proper key names.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4652
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weather Underground Plugin

Post by kgschlosser » Mon May 01, 2017 8:02 pm

I gotta get to work tho.. I will check back in a little later maybe an hour or so and see how you made out.
If you like the work I have been doing then feel free to Image

loveleejohn
Experienced User
Posts: 129
Joined: Thu Dec 10, 2015 12:09 am

Re: Weather Underground Plugin

Post by loveleejohn » Mon May 01, 2017 8:04 pm

No hurries kg! I will have to nibble at this because I am certain the issue is based on my lack of understanding. Hope you have a great time at the job. Cheers for now.

User avatar
kgschlosser
Site Admin
Posts: 4652
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weather Underground Plugin

Post by kgschlosser » Mon May 01, 2017 9:57 pm

LOL my job is at my house. so I don't have to go very far... But have you had any success??
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4652
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weather Underground Plugin

Post by kgschlosser » Mon May 01, 2017 10:02 pm

copy and paste this into your tree and see if it runs

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-beta6">
    <Macro Name="Four Day Forecast" Expanded="True">
        <Action>
            WeatherUnderground.Forecast(u'CO', u'Evergreen', u'', False, True, False, False)
        </Action>
        <Action>
            EventGhost.DumpResult()
        </Action>
    </Macro>
</EventGhost>

and also try this one as well

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-beta6">
    <Macro Name="Four Day Forecast" Expanded="True">
        <Action>
            WeatherUnderground.Forecast(u'CO', u'Evergreen', u'', False, True, False, False)
        </Action>
        <Action>
            EventGhost.PythonScript(u'eg.result = eg.result.May01')
        </Action>
        <Action>
            EventGhost.DumpResult()
        </Action>
    </Macro>
</EventGhost>
If you like the work I have been doing then feel free to Image

loveleejohn
Experienced User
Posts: 129
Joined: Thu Dec 10, 2015 12:09 am

Re: Weather Underground Plugin

Post by loveleejohn » Mon May 01, 2017 10:53 pm

Must be awesome to work from home. Hiring?! Lol. jk. Anyways I tried your magical button that's always been in eventghost that I of course have never seen until today! :lol: Magically it dumps a complete payload into the log area in eventghost. Now I'm gonna use what I just saw Jonib posts in my other forum post to see if I can pull this together. I think this is gonna be a nifty plugin!

Post Reply