Weather Underground Plugin

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

Re: Weather Underground Plugin

Post by kgschlosser » Mon Apr 10, 2017 6:30 am

ok only 1 action to go.
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 12, 2017 2:25 am

I played around with it a little bit today. Most things seem to be working well. I here you on the copy/paste but agree with "loveleejohn" that the location should be set in the plugin config, not in each actions config. If you need multiple locations, you can multiload the plugin, or add an action to change the location. I was wondering if you could add an option to return "raw Json"? Similar to how you have the "return xml string" action setup currently.

Just an FYI to anyone that's new to Weather Undergrounds api, the free keys they give out are limited to 10 requests a minute. They don't usually shut you off but something to keep in mind when testing stuff.

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

Re: Weather Underground Plugin

Post by kgschlosser » Wed Apr 12, 2017 3:11 am

yokel22 wrote:I played around with it a little bit today. Most things seem to be working well. I here you on the copy/paste but agree with "loveleejohn" that the location should be set in the plugin config, not in each actions config.
OK there are 2 requests for this I will make it that way
yokel22 wrote:If you need multiple locations, you can multiload the plugin, or add an action to change the location.
how about this??. I will add the global location information. but I will leave the ones in the action as well they will just auto populate with the global ones. that way all you would need to do is to change it in that actions config. and if you pass no parameters in the call to the action it will use the global ones. doing it this way is always going to return the plugins data object.

yokel22 wrote:I was wondering if you could add an option to return "raw Json"? Similar to how you have the "return xml string" action setup currently.

I am going to add some other options to this as well. I am going to have a checkbox for xml and one for json. and then a box for object or str. this way it will return data any which way you want.
sure thing this is an easy one i can simply ask weather underground for the json data. question would you rather it be returned as a string or would you like to have it returned as a json object (dict)?
yokel22 wrote:Just an FYI to anyone that's new to Weather Undergrounds api, the free keys they give out are limited to 10 requests a minute. They don't usually shut you off but something to keep in mind when testing stuff.
I believe i mentioned this.. but the thing to remember is you get the 10 free calls per minute no matter what level of API key you select. the highest tier allows for all of the API to function. so get the best one. because for a single seat use 10 calls per minute is a whole lot. I have been thinking about adding a polling thread for current weather, 4 day forecast and 10 day forecast that would only trigger an event if something has changed. and the user could select the polling interval and would produce a warning if it is set over 10 calls per minute. personally i think a call once every 10 is a lot but if you are using this to grab data from a PWS then yeah maybe once a minute.
If you like the work I have been doing then feel free to Image

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

Re: Weather Underground Plugin

Post by kgschlosser » Wed Apr 12, 2017 4:22 am

well give this whirly bird a twirl..
I have added the global location and metric.
I have also changed the xml_string. so this is how it works


xml checked
elementree\json object unchecked
string unchecked
----------------------
returns parsed plugin data object

xml checked
elementree\json object checked
string unchecked
---------------------
returns ElementTree object

xml checked
elementree\json object unchecked
string checked
----------------------
returns WU's xml response

now you have to have either the JSON checked or the string checked when xml is unchecked

xml unchecked
elementree\json object checked
string unchecked
----------------------
returns json object

xml unchecked
elementree\json object unchecked
string checked
----------------------
returns WU's json response


Everything is backwards compatible. but if you want the location information to properly populate after upgrading the plugin you will need to go into the plugin config panel and set the proper information.
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 12, 2017 5:34 am

Json object. Mainly so I don't have to alter current scripts I have too much. Ill give the update a go here.

Json functions seem to be working well. Event payloads are populating correctly now also.

Here are a couple of examples of parsing the json response("you'll need to change the location in the 1st line").

10day forecast:

Code: Select all

item = eg.plugins.WeatherUnderground.Forecast10Day(u'66203', u'Shawnee', u'', False, False, True, False)
for day in item['forecast']['simpleforecast']['forecastday']:
    print day['high']['fahrenheit']
    
for text in item['forecast']['txt_forecast']['forecastday']:
    print text['title']
    print text['fcttext']
Current Conditions:

Code: Select all

item = eg.plugins.WeatherUnderground.Conditions(u'66203', u'Shawnee', u'', False, False, True, False)
print item['current_observation']['temp_f']

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

Re: Weather Underground Plugin

Post by kgschlosser » Thu Apr 13, 2017 6:12 am

attached is a new version of the plugin.

adds automatic returns for celsius and fahrenheit depending on if the action is set to metric or not i forgot to add those.
added a second class to eg.plugins. so now there is eg.plugins.WU and eg.plugins.WeatherUnderground it's a typing saver.
added internationalism support.


just to let ya know.. you can also set the action outside of a python script. you will have to use eg.result instead of item=eg.plugins.WeatherUnderground.Action().. just in case you like seeing something other then just "Python Script" in the log..

@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
If you like the work I have been doing then feel free to Image

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

Re: Weather Underground Plugin

Post by kgschlosser » Thu Apr 13, 2017 8:19 pm

now if by chance an attribute has a space in it.. then simply change the space to _


as an example..

if there is an item in the WU api that is "weather forecast" and you want to access it directly. and also it doesn't matter if the attribute is uppercase or lowercase.

this is how you would do it.
item.weather_forecast

you are also able to get the data just like it was a dict as well.. this is all lowercase to access the data this way and if there is a space leave the space. this is also the mechanism to use if you want to grab both the metric and imperial data

Code: Select all


print item.Apr14['high']['fahrenheit']
print item.Apr14['high']['celsius']

# this will work also
print item['apr14']['high']['fahrenheit']
print item['apr14']['high']['celsius']

I have also added a new feature as well. as soon as i release the next version it is going to include polling which will trigger an event if the data has changed. but if you do not want to use the polling and want to set up your own. if you use the data class i have made it gives you the ability to update the data directly from inside of the item so if you set the data class into a global you can simply do the following.

Code: Select all


eg.globals.SOME_FORECAST.Update()

if eg.globals.SOME_FORECAST.IsDirty():
    do your code here.
the nifty thing about how i set this piece up is that if you want to know if the data for a specific day has changed. so if you want to know if todays forecast changed and don't care if tomorrows changed

Code: Select all

import datetime

date = datetime.datetime.now()
forecast_date = date .strftime('%b%d').lower()
forecast = eg.globals.SOME_FORECAST[forecast_date]

forecast .Update()

if forecast.IsDirty():
    do code here

you can call Update from any sub container in the data class and it will update the whole class. but it sets the dirty flag from sub container down. meaning that if the forecast for tomorrow if dirty then the main container that houses all of the days is also going to be dirty. but if tomorrow nights has not changed then the dirty flag ends at tomorrow and does not include tomorrow.night.

it's a pretty neat how i set it up to work. I will be adding for flexibility to the parser because at the moment it only work if you activate it from the base class that contains all of the days. but i am going to include sub containers as well so you can print out for a specific day instead of all of them simply by doing

Code: Select all

# this will include day and night forecast
print str(item.Apr14)

# this will be only the night
print str(item.Apr14.Night)
after the polling this is going to be the next addition.

if there is anything else you feel should be added let me know.. but i do want to give some code snippets


How to get the date key for accessing today

Code: Select all

import datetime

date = datetime.datetime.now()
forecast_date = date .strftime('%b%d').lower()
forecast = SOME_FORECAST[forecast_date]
how to get the date key for accessing tomorrow

Code: Select all

import datetime

date = datetime.datetime.now()
date += datetime.timedelta(days=1)
forecast_date = date .strftime('%b%d').lower()
forecast = SOME_FORECAST[forecast_date]
and if you wanted to get the specific hour for the hourly forecast for today

10:00 AM

Code: Select all

import datetime

date = datetime.datetime.now()
forecast_date = date .strftime('%b%d').lower() + '10'
forecast = SOME_FORECAST[forecast_date]
10:00 PM

Code: Select all

import datetime

date = datetime.datetime.now()
forecast_date = date .strftime('%b%d').lower() + '22'
forecast = SOME_FORECAST[forecast_date]
for tomorrow

10:00 AM

Code: Select all

import datetime

date = datetime.datetime.now()
date += datetime.timedelta(days=1)
forecast_date = date .strftime('%b%d').lower() + '10'
forecast = SOME_FORECAST[forecast_date]
10:00 PM

Code: Select all

import datetime

date = datetime.datetime.now()
date += datetime.timedelta(days=1)
forecast_date = date .strftime('%b%d').lower() + '22'
forecast = SOME_FORECAST[forecast_date]
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 » Fri Apr 14, 2017 3:22 am

I just want to let you know that you can iterate the data class that i made to represent the weather data.
Yep, i just have a handful of fairly complicated scripts that were making calls directly to the api. Essential, just waiting to be worked into a plugin, ya just beat me to it :D They were all setup for Json responses and I just wanted to do some quick testing without having to rework a bunch of stuff. I plan on switching things over to the data class you setup here when i get some free time.

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

Re: Weather Underground Plugin

Post by kgschlosser » Fri Apr 14, 2017 3:53 am

that data class is actually pretty cool how it's set up. and with the addition of the IsDirty() and also having the ability to update the data in the class makes it very handy. especially if more then one script uses it.. there is no need to make another call to the plugin just store the bugger in eg.globals. I almost want to go out and buy a PWS now.. LOL. This pretty much adds all the major brands of weather stations to EG. Tho i do wish there was a direct API for just the weather stations.
If you like the work I have been doing then feel free to Image

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

Re: Weather Underground Plugin

Post by kgschlosser » Fri Apr 14, 2017 4:01 am

There is one thing I may need to change. and this is the only sub container so far that has this issue.. but the forecast and forecast10day actions all have a nice text of the forecast. and it's in imperial and metric. right how I have them housed with all of the rest of the forecast data. unlike something like high or low the only 2 things in there are english and metric. right now it's not causing an issue because i do not have them added to the automatic metric selection. so i was thinking about putting them in their own container I feel this would conform more so to how the hierarchy works. but it will also allow for the automatic return of english or metric.
If you like the work I have been doing then feel free to Image

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

Re: Weather Underground Plugin

Post by kgschlosser » Sat Apr 15, 2017 9:25 pm

OK ladies and gents. I have the start of a data class layout for you it's an ascii vertical tree diagram showing attribute names and and if there is a class under that attribute.. It's a work in progress so nbe patient. as there is a HUGE amount of data to sift through. I am going to add a class layout tab in the config dialogs that will populate with the actual data. but for those of you that like ascii tree diagrams.. here goes
Attachments
weather underground class layout.zip
(2.51 KiB) Downloaded 111 times
If you like the work I have been doing then feel free to Image

kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: Weather Underground Plugin

Post by kkl » Sun Apr 16, 2017 10:22 pm

Hi,

I just tried 1.2b (first install of any version). With any of the default actions, I'm getting a traceback error:

Code: Select all

Weather Underground: Current Conditions
   Error in Action: "Weather Underground: Current Conditions"
   Traceback (most recent call last) (1722):
     File "C:\Program Files (x86)\EventGhost\eg\Classes\ActionBase.py", line 170, in CallWrapper
       return self(*args)
     File "C:\ProgramData\EventGhost\plugins\WeatherUnderground\__init__.py", line 332, in __call__
       payload = func(loc1, loc2, pws_id, metric, xml, data_obj, data_str)
     File "C:\ProgramData\EventGhost\plugins\WeatherUnderground\wu\__init__.py", line 411, in __call__
       return update()
     File "C:\ProgramData\EventGhost\plugins\WeatherUnderground\wu\__init__.py", line 379, in update
       except ET.ParseError:
   AttributeError: 'module' object has no attribute 'ParseError'
Still on EG r1722. I'm pretty sure the configuration is correct. Is there anything else I might be doing wrong?

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

Re: Weather Underground Plugin

Post by kgschlosser » Mon Apr 17, 2017 1:19 am

well that's an error due to another error. but their server could be overloaded. if you select to return a string then do print eg.result after the action it should print out the exact response from WU without triggering a traceback error. this will at least tell you what the error is from WU then we can go from there
If you like the work I have been doing then feel free to Image

kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: Weather Underground Plugin

Post by kkl » Mon Apr 17, 2017 4:24 am

Thanks very much for the guidance. My bad, as expected. The error was an unknown API key.

The default in the WU API form field is "https://www.wunderground.com/?apiref=", so I mistakenly grabbed the referral URL that started with that string. That caused the error. I then substituted the Key ID, still with the full https://... Error with that. It wants JUST the API Key ID (no https://...).

Now it works great. Very nice piece of programming, as usual.

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

Re: Weather Underground Plugin

Post by kgschlosser » Mon Apr 17, 2017 5:22 am

well I have to fix the traceback issue now that i know one exists. this way i can properly handle the exception and generate a traceback that will actually inform you that you gave it a bad api key


It's not bad. I will be releasing another version soon enough. I am almost done with the polling bits. but i also have added a tree style layout that shows you the attribute names and the data.. and it even will display the icon if there is one.

I have also added some more automatic metric/imperial returns that i had missed previously. I just have to finish up the dialog for monitoring the various polling threads.. the way I have set that up is you will be able to start a polling thread for any of the actions except the radar one. and specify an interval for each individually. but you will have the ability to add and remove polling threads but also start and stop them. I am going to make actions for starting and stopping the threads as well.


the really crappy thing about the WU APIis that it looks as tho 20 different people made the different API pieces because they all have different keywords. as an example. if you want to get the temperature for a current condition the attributes would be temp_f and temp_c and for a 4 day forecast it would be a holder called temp and under that holder would be f and c or fahrenheit and celsius it a real pain because there is no standard to it. in the list below are the different variations of mated metric to imperial and they could be the actual attribute name or they could have these added to the end of the attribute name or they could have an _ and the measurement type added to the end of the attribute name. so to get a metric measurement for temp it could be. c, celsius, temp_c, temp_celsius, tempc, tempcelsius the various different ways makes it a real annoyance. and I have thought about changing the data class to correct this issue and standardize the API across all actions. but then it won't match what WU's API is. i really don't know which way to go on this i really do like having a standard across the board it removes any unneeded complications. tho it would be a lot more code to key up because i would have to make some kind of an index with all of the attribute names to point to the new name to use..

Code: Select all

METRIC    IMPERIAL

    c            f
    m           i
    km         mi
    mb         in
    cm         in
    mm        in
    mb         inches
    kph        mph
    metric    english
    metric    in
    celsius    fahrenheit

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

Post Reply