Weather Underground Plugin

Questions and comments specific to a particular plugin should go here.
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 May 03, 2017 4:01 am

I really did try to make this to be a very powerful plugin for the more advanced user. but I also tried to make it extremely easy to do the basic things as well. there is just such a massive amount of data that is gotten from WU that this was the best way i could think of for making the plugin extremely flexible but also maintain ease of use.

I am still working out more of the formatting stuff for the text output this way you will be able to wrap str() around any of the data classes and it will output the formatted data for that data set. and by me just now trying this I just thought of how to do it.. w00t.. sometimes ya have to say it in order to think of the best way. I am going to make it so that each layer starting with the last is responsible for it's own data meaning that if you call str() on the parent. the children have str() called on them by the parent. so the data ends up being formatted properly. so if you call str() directly on the child then the data will come out properly only for that child.

I am going to switch some things up with this plugin. and I really hate to do this. But I am thinking it may change the API a bit I will try my best to not have it do that but it may happen. so if there is something specific you would like to see done please let me know. I am also going to make a different object container for each of the different action types. that can be checked if needs be for what type it is by doing

Code: Select all

isinstance(eg.result, eg.plugins.Data.FourDayForecast) 
if it is a 4 day forecast it would return True. I think it's going to allow for a cleaner code. and make it easier for me to change/update/add to it. I am going to split the code into files based on the action. to make it easier to get right to where i need to be to make the changes.
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 May 03, 2017 4:31 am

I do recall you mentioning you were going to make it agnostic in scale. I posted that as more of an quick example for loveleejohn. That's not really what i'm doing with it. I'm parsing out specific values for a web app. Thanks for the tips.

Maybe i'm blind, but i still don't see it. icon is the last tree item i see. It does return relative humidity when i request it via script though.
wuConfig2.jpg
Last edited by yokel22 on Wed May 03, 2017 6:59 am, edited 1 time in total.

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 May 03, 2017 6:11 am

don't know here is a screen shot of mine. i just did it. and you can see the time and date in my screen capture.
wu.png
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 » Wed May 03, 2017 6:12 am

have you tried to just simply ask the class for the attribute?
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 » Wed May 03, 2017 6:13 am

Oh also change the location. it could be that maybe for some reason WU is not reporting it for the location you are using
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 May 03, 2017 6:38 am

It does return the humidity value. Just doesn't populate in the data helper. Not sure, seems like something in the icon field that's not allowing it to continue the process. I'll look at my whole eg.result to see if all the keys from your screen are there. I imagine they will be. I'm in Kansas city, the returns should be almost identical to what your seeing in evergreen.

I'm running latest rc of 5.0

** Update **

Okay everything below icon is returning, but missing the icon. Here's my full return:

Code: Select all

      Current Conditions
          Location
              Shawnee, Kansas 66203 US
              Latitude: 39.02000046
              Longitude: -94.70999908
              Elevation: 305.1
          Station ID: KMKC
          Observation Location
              Shawnee, KS US
              Latitude: 39.11999893
              Longitude: -94.58999634
              Elevation: 758 ft
          Observation Time: Wed, 03 May 2017 00:54:00 -0500
          Currently: Overcast
          Temperature: 55 F (13 C)
          Dew Point: 51 F (11 C)
          Heat Index: NA
          Wind Chill: NA
          Feels Like: 55 F (13 C)
          Humidity: 86%
          Wind: Calm
          Wind Direction: North
          Wind Direction (degrees): 0
          Wind Speed: 0
          Wind Gust: 
          Precip Last Hour: 0.00 in (0.0 mm)
          Precip Today: 0.00 in (0.0 mm)
          Pressure: 30.01
          Pressure Trend: -
          Visibility: 10.0
          UV Index: 0
** Update 2 **
I noticed this error when testing the populate function. I think i've always been getting it, just didnt' notice 'till now. Should help you narrow down what's going on with the population error.

Code: Select all

Exception in thread Thread-35:
Traceback (most recent call last):
  File "threading.pyc", line 532, in __bootstrap_inner
  File "threading.pyc", line 484, in run
  File "C:\ProgramData\EventGhost\plugins\WeatherUnderground\__init__.py", line 505, in Populate
    iter_data(root, data)
  File "C:\ProgramData\EventGhost\plugins\WeatherUnderground\__init__.py", line 495, in iter_data
    str(pil.tobytes())
  File "PIL\Image.pyc", line 512, in __getattr__
AttributeError: tobytes
Last edited by yokel22 on Wed May 03, 2017 6:18 pm, edited 1 time in total.

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 May 03, 2017 7:20 am

ok i will take a look at the code. i may have put a return instead of a continue in the code when it tries to load the icon and fails
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 » Wed May 03, 2017 1:44 pm

@loveleejohn

do you even read my posts??

I explained what that data class help tab was for. It shows you the layout of the class. word for word. it even shows you the purdy icon. which I am going to change into a wx bitmap so it would be extremely easy to use
:( I'm almost certain that I read every post in the forum with a focus on those that began with @loveleejohn. That said, for a non-coder like me python is akin to drinking from a firehose at times so there is a possibility that I may have missed it.... Could you be referring to this block?
@yokel22

I still have to key up complete docs on how the data classes are organized. but for the most part if we use forecast as an example.. in the WU api they had 2 containers for the 4 days. and in one of the containers they had printable forecasts for day and night for each of the 4 days and in the other is the metrics for each of the 4 days. so what i did was combined everything. so you now have one container for each of the days with a sub container for night and everything else is in the main container. it's easier to access all of the information this way. so if you wanted to access forecast data for say April 14th

data in item.Apr14

metric - text forecast with metric data
period - ??
pop - ??
high - **High temps
avehumidity - **Average Humidity
snow_day - **Expected snowfall during the day
qpf_day - ??
title - day name
maxwind - Max wind speed
imperial - text forecast with imperial data
low - **Low temps
conditions - text of the weather conditions
snow_allday - **expected snowfall all day
minhumidity - **Min Humity
date - sub container that houses all the date information
avewind - **Average wind speed
icon - downloaded and converted icon for the conditions (is a python file like object)
maxhumidity - **Maximum humidity
snow_night - **Expected snowfall at night
skyicon - Never seen this populated
qpf_night - ??
night - sub container holding night time forecast data

** will automatically return imperial or metric data depending on what is sent to the action

I just want to let you know that you can iterate the data class that i made to represent the weather data. use the version i have attached to this post before doing this.

Code: Select all

item = eg.plugins.WeatherUnderground.Forecast10Day(u'66203', u'Shawnee', u'', False, True, False, False)

    # the _ is the date used to access the forecast data if calling it directly
    # we don't need it but we still have to account for it being returned.

    for _, forecast in item:
        print '%s, %s' % (forecast.title, forecast.date.pretty)
        print '    High Temp: %s\xB0 F' % forecast.high
        print '    Low Temp: %s\xB0 F' % forecast.low
Although learning is dependent on both the instructor's clarity and the student's ability I am increasingly persuaded that the difficulty here lies in my own abilities to synthesize this volume of data. I just might have to throw up the flag of temporary surrender until I can gain a better understanding of the python monster. lol... Thanks for trying kg.

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 May 03, 2017 3:43 pm

@loveleejohn

No No don't throw in the flag. that's the worst thing to do.

it is a whole lot of information...

we can start back from the beginning if you want and I can go through one step at a time how to use this thing.. and explain each bit. and if you do not understand it.. say that... because if there is one piece that is slipping through then the rest is not going to make sense.

DO NOT GIVE UP.

tell me where to start off and we can go from there

and the post about you not reading my posts was a joke. I said it because I to also glance not always reading 100% of what was there. and that is how I intended it to be.. I'm sorry if I came across in a bad way. was not my intention. That is one of this really shitty things about the internet. some things when they get stated don't have the intended outcome..

one of the biggest reasons i want you to continue learning this is because this one specific plugin can show you how python really works and how to bend it to make it do what you want. It will also give you an understanding of python data structures which is probably hands down one of the hardest bits to understand. but once you do will really shed a lot of light on how python works.
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 » Thu May 04, 2017 12:59 pm

Hey there kg. I have really come to appreciate all of your help in this forum. I think python was just starting to overwhelm my senses to be honest. I really like this program a lot but I think I stuck my head directly in the path of the firehose instead of using an 8 ounce glass which resulted in me getting a bit overwhelmed. I'm gonna take your advice to hang in there but I'm gonna be more careful to dial back on my portions so I can fully absorb this stuff.

There is a dizzying feeling of success when a tiny and admittedly often insignificant bit of code does what I expected, which then drives me further into the deluge with my mouth wide open but I think I've come to realize that as with most things, python must be learned in pieces. I wasn't particularly upset over your joke, so definitely don't let go of your humor which happens to be a very refreshing thing in a coding forum! Lol. I think my issue was primarily with feeling somewhat overwhelmed with the difficulty I was having in grasping some python concepts.

Having said these things, I think that my challenges resolve to 2 primary areas.
1. Limited understanding and familiarity with Python and coding in general.
2. Difficulty in compensating python rules for implementation with the Eventghost application.

I have started working on the first issue by enrolling in python class at codeacademy and studying the python lessons at https://www.tutorialspoint.com/python/c ... xample.htm where the examples given have been exceedingly helpful.
I have attempted to resolve the second issue by reading through the entire eventghost manual but it appears that many of the elements do not have accompanying examples which I think might be very helpful to other beginners like myself. I realize that eventghost is a volunteer society however, so I can hardly put the blame on the team who all seem to be doing so much to keep the program in its current successful status.

In regards to this plugin I think the things that you and yokel22 have kindly shared have finally helped me to get the intended behavior out of Eventghost. Here's what I've done to get the computer to print and announce the current local temperature audibly on my computer.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1722">
    <Macro Name="Print Current temperature in log" Expanded="True">
        <Action>
            WeatherUnderground.Conditions(u'CO', u'Evergreen', u'', False, True, False, False)
        </Action>
        <Action>
            Speech.TextToSpeech(u'IVONA 2 Brian - British English male voice [22kHz]', 0, u'{eg.result.temp_f} degrees fahrenheit', u'', 100, u'Speakers (2- Logitech USB Headset)')
        </Action>
        <Action>
            EventGhost.PythonScript(u'print eg.result.temp_f')
        </Action>
    </Macro>
</EventGhost>
For some reason I am getting some bleeding in the log even thought he code executes correctly. Here's a screenie of the bloodbath. Lol.
Capture3.PNG

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 » Thu May 04, 2017 2:12 pm

ok this is how eg.result works..

eg.result is the return of result of an action. so you have the print eg.result.temp_f after the speech action.. and the speech action has a None for a return or result of it.

now i believe one of the errors could be due to how you are passing the information to it.

So as a pointer. if there is a parse option in an action then you have the ability to pass a python command to the action. anything enclosed within the curly brackets is not just for variables. it is evaluated by the python interpreter just as if you actually keyed the code into a file and ran it that way. this allows for the dynamic creation of code and a way to run that code.

so doing this {eg.result.temp_f} degrees fahrenheit may cause issues because it is actually 2 pieces.. the whole thing is treated like it is a string when it is passed so what the plugin sees is this

"{eg.result.temp_f} degrees fahrenheit" Now i have never actually dove into the code for the parser. But from my basic understanding of how it works is it pulls the {eg.result.temp_f} out of that line so you end up with
"{eg.result.temp_f}" and "degrees fahrenheit" then it removes the curly brackets "eg.result.temp_f" "degrees fahrenheit" and then evaluates the part that had the curly brackets."eg.result.temp_f" "degrees fahrenheit" the evaluation is going to compile and run that piece as if it was code so as you can see there is no real connector between the 2 parts. so how does it know to join them?. Now for some reason it is but I do not know if this is causing a problem with the speech plugin because if it. but the best way to do this is actually make it so that the whole thing gets evaluated. not just just half of it. {eg.result.temp_f + 'degrees fahrenheit'} now this will be ran as python code and the 2 will be joined properly this is actually a really nice way to go the reason being is if you have a variable that is a number and not a string but you want to make it a string and add it to some text for the speech plugin to speak { 'this is the number ' + str(eg.globals.some_number)} it gets a lot more in depth then that. and if you like i can go into ity but i will do that in the coding corner thread

so rule of thumb. if you want to perform a specific task on eg.result it has to be done right after that specific action has run. OR you have to move the contents of eg.result to a different container. if the task you need to perform happens after another action has run.. below is a little sort of flow chart of what takes place

So this is essentially how you have it set up


WU Action runs
data is put into eg.result from the action

Speech Action runs and accesses eg.result.temp_f
speech plugin sets eg.result to None because it has no return data

Python Script Action runs
script goes to print eg.result.temp_f but there is no temp_f in a "None Type" object
this is because the speech action set eg.result to None



This would work

WU Action Runs
data that is return from the action gets set into eg.result

PythonScript Action runs
script puts data into eg.globals.temp_data
eg.globals.temp_data = eg.result

Speech Action runs
speech action now has to access eg.globals.temp_data because the PythonScript action has set eg.result to None
{eg.globals.temp_data .temp + 'degrees fahrenheit'} <--- correct way

Python script Action Runs
print eg.globals.temp_data.temp


and this would work as well

WU Action Runs
data that is return from the action gets set into eg.result

PythonScript Action runs
script puts data into eg.globals.temp_data and prints the temp
eg.globals.temp_data = eg.result
print eg.result.temp

Speech Action runs
speech action now has to access eg.globals.temp_data because the PythonScript action has set eg.result to None
{eg.globals.temp_data .temp + 'degrees fahrenheit'} <--- correct way
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 » Thu May 04, 2017 2:13 pm

and there is an error in the speech plugin that is why you are getting the error about the suffix. i am going to fix this right now and get it into the final release of EG


Scratch that.. this error has been fixed. i didn't realize you were running 1722 If you run RC2 the speech plugin has had an overhaul.
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 » Thu May 04, 2017 2:38 pm

Thanks for the thorough explanation kg. I was able to completely understand your examples and I can see now the syntax issue that I inadvertently created. The only remaining question that I have now is what the ".temp" is for.

If we set eg.globals.temp_data = eg.result earlier, then why wouldn't we use {eg.globals.temp_data + 'degrees fahrenheit'} instead of {eg.globals.temp_data .temp + 'degrees fahrenheit'} under the speech action? Similarly, why do we print eg.result.temp instead of print eg.result?

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 » Thu May 04, 2017 7:21 pm

because we did this

eg.globals.temp_data = eg.result

not this

eg.globals.temp_data = eg.result.temp


the temp_data was not for temperature data. it was for temporary data. I stored the whole WU data class not just the temperature. I did that as an example so you would be able to access the whole data class later and not just a single piece of it..


this is the really badass thing about it.. the way I have set this whole thing up is so that you can run the action at startup and do the eg.globals.whatever_name_you_want = eg.result
and never have to run the action again.

then you can at any point of your liking in any macro do eg.globals.whatever_name_you_want.Update(). and it will go and repopulate all of it's information without the need to run the action again.
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 » Thu May 04, 2017 7:25 pm

and the .temp is for temperature


you have been using temp_f

well there is a temp_c also.

and the reason for specifying if you want to use metric or imperial in the action dialog is so that the data container will return the proper one

but in order for this mechanism to work you have to not specifically ask for f or c just ask for the temp


it works with anything that has an imperial/metric ending

wind_mph
wind_kph

would be just wind

wind_gust_mph
wind_gust_kph

would be wind_gust
If you like the work I have been doing then feel free to Image

Post Reply