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.
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):
- METAR (their xml doesn’t seem too nice to parse and their text only data looks like it’s getting right out of an old mainframe)
Using the script
I’ve tried to make the API as simple as possible, hiding most of the complexity in the script component.
To start using the weather component, you need to create a new instance of the script and register callbacks. Those are functions that will be called when new weather data is available.
Set WeatherController = GetObject("script:" & LIB_FOLDER & "Weather.wsc") WeatherController.RegisterCallbacks GetRef("OnLocations"), _ GetRef("OnWeather"), _ GetRef("OnAlerts"), _ GetRef("OnForecast"), _ GetRef("OnCameras"), _ GetRef("OnError") 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.
WeatherController.SetProvider "WUnderground" ' Default is True WeatherController.UseMetricSystem = True ' This will be ignored by the WUnderground provider as it does not use a license key WeatherController.SetLicense "my_id", "my_key"
Once the API is stable, I’ll update this post and if you want to help me add support for the other weather site, let me know!
If you want 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.
I’m still working on the script and the API is still in flux, but you can get a look at it here.