Multi-provider weather component
Published on July 12, 2009 By Littleboy In DesktopX

Hey all!


07/20: I'm looking for a few weather widget authors that would be willing to update their objects using the component and provide feedback. I'll be providing help and guidance on the use of the component if needed. Widgets that make complete use of weather.com data are preferred (current conditions + forecast with as much info presented to the user as possible).

As of today, the Weather.com provider is mostly complete and should be usable as a replacement for the old script. Weather Underground still needs a bit more work, especially on the parts that aren't available with weather.com (cameras, alerts).

If you're interested, you can PM me or send me an email. I'm also available on IRC (irc.stardock.com) under the nick "Julien".


It seems there wasn't enough Weather threads, so I decided to have my own .

For the past few days, I've been working on a weather script component. It takes the form of an independent .wsc script file that you reference in your widget script (setting up license info and registering callbacks), calling a few methods and getting weather/location/alert data in the form of a script object with several properties.

Using this new script means rewriting a lot of the existing weather objects script, only keeping the UI handling in the widget scripts and delegating all the weather stuff to the component. It's not a short term solution for authors that need to update their widgets in the next few days, but I think it's the easier and more maintainable solution in the long run, as it would finally do away with the duplicated and slightly tweaked weather code in all weather widgets.

Note: This thread is to discuss the weather script component only. If you want to ask questions about the original weather script, existing weather widgets updates or just complain about TWC.com/Stardock/etc..., you can do so here, here and here.

The plan is to support several widget providers in the same script, in a mostly transparent way. Right now, I'm planning to have the following providers (in this order):

  • Weather Underground - 90 %
  • Weather.com (TWC) - 95 %
  • NOAA
  • WeatherBug
  • METAR
  • Accuweather

Using the script

I've tried to make the API as simple as possible, hiding most of the complexity in the script component. In the following, the Weather Script Component will be called WSC.

To start using the script, you need to create a new instance of the WSC and register callbacks. Those are functions that will be called when new data is available or if an error happened somewhere.

Code: vbscript
  1. Set WeatherController = GetObject("script:" & LIB_FOLDER & "Weather.wsc")
  2.   
  3. WeatherController.RegisterCallbacks GetRef("OnLocations"), _
  4.           GetRef("OnWeather"), _
  5.           GetRef("OnAlerts"), _
  6.           GetRef("OnForecast"), _
  7.           GetRef("OnCameras"), _
  8.           GetRef("OnError")

You can then get a list of supported providers to let the user choose the one he wants, of simply hardcode the provider you want. If the provider requires a license key, you can also set it at this time, as well as the unit system to use.

Code: vbscript
  1.  
  2. WeatherController.UseMetricSystem = True    ' Default is True
  3. WeatherController.SetLicense "my_id", "my_key"    ' This will be ignored by the WUnderground provider as it doesn't use a license key, for other providers, check the return value to know what is required
  4. retCode = WeatherController.SetProvider("WUnderground") ' you can use the WeatherController.Providers property to get a list of <id, display name> pairs
  5.  
  6. If (reCode <> E_OK) Then
  7.   MsgBox "Invalid Provider!"
  8. End If

Once your weather object is setup, you can start making queries. The WSC uses a single query object for all requests, so that we don't need to implement a separate method for each type of request.

To get a new query object, you can either create a new instance of a WeatherLocation object, or use the helper method I added to the WSC. You can then set properties on the query object, or use the CustomQueryString property (useful when you want to do a query using a search string entered by the user).

Code: vbscript
  1. Dim query, retCode
  2. Set query = WeatherController.GetQueryObject()
  3. query.AirportCode = "KMQE"
  4. retCode = WeatherController.GetWeather(query)
  5.  
  6. Select Case retCode
  7.   Case E_OK ' query accepted and request sent
  8.    ' Continue
  9.   
  10.   Case E_NOTIMPLEMENTED ' the chosen provider does not implement this method
  11.    MsgBox "Method not implemented!" ' should not happen with GetWeather obviously!
  12.    
  13.   Case E_NOTAVAILABLE ' the query you used is not supported by this provider/method (for example, you called GetWeather with a country name only)
  14.    MsgBox "Query type not available!"
  15.    
  16.   Case E_ERROR ' you forgot to set a provider or your query is empty
  17.    MsgBox "Error!"
  18. End Select

If an error happens after the request has been sent, you will get an error code and message through the OnError callback (for exemple, if there is a parsing error or if the response is empty, etc.)

If all goes well, we should get a response and our OnWeather callback will be called

Code: vbscript
  1. Sub OnWeather(weatherInfo)
  2.   ' Update your object UI using the new weather information
  3. End Sub

Contributing

A first test version is now available. Inside the Build folder, you will find 3 files:

The test object is using the minified version and is also a bit pre-processed, so if you want to check the script, you probably want to use the original version

If you plan to use the script and there is some functionality that seems to be missing, post here or PM me and we'll see if it can be added.

Limitations

  • Forecast might in some case be duplicated with Weather Underground (you will get separate forecast objects of the detailed forecast followed by the normal ones)
  • Some dates have the wrong timezone (needs some tedious checks to make sure we get everything right)
  • Alerts codes use magic values directly from the provider instead of constants from WeatherConstants

Download

Warning: The API is now relatively stable, but it might still change a little bit before 1.0, so know that you might have to slightly adjust your widget script when you get a new version of the component.

The latest version can always be downloaded from here.

Changes

  • 07/12/09: Weather Underground provider, basic architecture in place.
  • 07/13/09: Support for external providers, helper component & error codes. Station name&type + UV/Solar radiation available.
  • 07/15/09: Forecast for Weather Underground. Date parsing, misc stuff
  • 07/16/09: Weather.com provider, with caching (locations & weather only). Added support for city-only response for Weather Underground.  
  • 07/17/09: Added forecast for Weather.com. Better parsing of dates in all providers. Added contants for weather codes.
  • 07/18/09: Added cameras support and cache to Weather Underground Provider
  • 07/20/09: Finished Weather Undeground implementation (icon code is now converted to proper value)

Comments (Page 1)
2 Pages1 2 
on Jul 12, 2009

Thanks for the help

on Jul 12, 2009

I was wondering when you would show up.    Thanks.

ZubaZ starts rereading so he can at least fake understanding.

on Jul 12, 2009

yes, thanks

 

 

 

 

fyi

 

It's not a short term solution for authors that need to update their widgets in the next few days,

 

authors don't need to update within the next few days - thay can take as long they want/need

 

the next few days is to go in a download a copy of your widget if you don't already have one

 

even after that, you can still contact and get a copy of what you need

on Jul 12, 2009

Was looking for this. Thanks Julien.

on Jul 13, 2009

Not that I understood a single line of that but this looks like the way to go. At least is is a step forward.

I am wondering though... How will provider selection and registration (

if any) be handled if the widget creator chooses not to put TWC logo and links on their work?

To use that service would require a completely different widget that meets TWC requirements,would it not?

on Jul 13, 2009

I am wondering though... How will provider selection and registration (if any) be handled if the widget creator chooses not to put TWC logo and links on their work?

I'm afraid this is going to be out of my hands. The component will populate a "promo" links dictionnary, so if there is something there, you know you have to show them in some way. But any specific UI requirements are left to the widget maker, the only limits I'll be able to enforce in the component are update limits per hour (and even that you can bypass by creating a new instance of the component on the fly each time you want to do a request).

As I just told sViz in message, I'm going to make it as easy as possible to respect the license for each provider, but in the end it's the widget maker responsibility to abide by the license. After all, if you do no want to respect the license, you can always get the xml feed directly and do whatever you want with the data...

BTW, either the widget maker or the end user will have to provider their id/key pair to make the component work with the TWC provider, so hopefully they will have a look at the license first.

To use that service would require a completely different widget that meets TWC requirements,would it not?

A widget with drawers for logo/links that you can hide will work too if you want to allow users to switch between providers. Although IIRC most of them require you to show credit information in some form (logo or text with a link to their website).

on Jul 13, 2009

Zubaz
Zubaz starts rereading so he can at least fake understanding.

I can't even fake it

on Jul 13, 2009

Littleboy

You and sViz are going to save this little part of the world, so many thanks.

"It seems there wasn't enough Weather threads, so I decided to have my own"

It's the weather. Everybody talks about it every day.

on Jul 13, 2009

Zubaz starts rereading so he can at least fake understanding

Hint...when you read....lip movements are a good indicator you aren't following it...

on Jul 16, 2009

Weather Underground should now be complete enough to use in a proper weather widget.

Download here and let me know if something isn't working properly or if you are missing some key functionality.

on Jul 16, 2009

Download here and let me know if something isn't working properly or if you are missing some key functionality.

I must be stoopid, I can't download it. 

on Jul 16, 2009

Littleboy
Weather Underground should now be complete enough to use in a proper weather widget.

Download here and let me know if something isn't working properly or if you are missing some key functionality.

Got it via right click "enregistrer la cible du lien sous..." "Save the link's cible under..." (can't translate this correctly )

But when launch the dxpack i get a DX error: "This file doesn't appear to be a valid DesktopX package"

Anyhow thanks for the work you're doing Julien

 

La prochaine fois que tu reviens en France et que tu passe par Paris faudra que je t'offre un verre.

on Jul 16, 2009

That's because it's a link to a page in the source tracker, not a direct link to the file (BTW I'll make a proper package once it's stabilized a bit more).

You need to first click on the link and then on the next page, click on View raw file. Note that the package contains fully processed files, so they aren't easy to look at or study.

Proper links to all files

on Jul 16, 2009

 You have to import the zip into DX, or you can change the extention to .dxpack. 

 

Julien, is it possible to allow simple syntax like "London" or "New York" and then return the list of matches? It only retreives locations via city/state or city/country.

on Jul 16, 2009

Julien, is it possible to allow simple syntax like "London" or "New York" and then return the list of matches? It only retreives locations via city/state or city/country.

After looking at what happens when you put a city only, it accepts it just fine and does the request, but sometimes the xml we receive is completely different from what is written in the specs.

It's basically just a list of (city, state) pairs with links to the webpage for that city. It doesn't have the info necessary for a weather request and you need to do another request for locations using one of the entry on the list to get proper airport or weather station codes.

I'm going to add some code to parse that list correctly and give you the list of city names.

Update: new build should show the list of cities correctly.

2 Pages1 2