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
- Set WeatherController = GetObject("script:" & LIB_FOLDER & "Weather.wsc")
-
- WeatherController.RegisterCallbacks GetRef("OnLocations"), _
- GetRef("OnWeather"), _
- GetRef("OnAlerts"), _
- GetRef("OnForecast"), _
- GetRef("OnCameras"), _
- 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
-
- WeatherController.UseMetricSystem = True ' Default is True
- 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
- retCode = WeatherController.SetProvider("WUnderground") ' you can use the WeatherController.Providers property to get a list of <id, display name> pairs
-
- If (reCode <> E_OK) Then
- MsgBox "Invalid Provider!"
- 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
- Dim query, retCode
- Set query = WeatherController.GetQueryObject()
- query.AirportCode = "KMQE"
- retCode = WeatherController.GetWeather(query)
-
- Select Case retCode
- Case E_OK ' query accepted and request sent
- ' Continue
-
- Case E_NOTIMPLEMENTED ' the chosen provider does not implement this method
- MsgBox "Method not implemented!" ' should not happen with GetWeather obviously!
-
- Case E_NOTAVAILABLE ' the query you used is not supported by this provider/method (for example, you called GetWeather with a country name only)
- MsgBox "Query type not available!"
-
- Case E_ERROR ' you forgot to set a provider or your query is empty
- MsgBox "Error!"
- 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
- Sub OnWeather(weatherInfo)
- ' Update your object UI using the new weather information
- 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)