Saratoga-Weather.org – Scripts – WeatherUnderground Forecast

Note: on 29-Oct-2014, WeatherUnderground changed their page layout for forecasts and necessitated a fairly complete rewrite of the WU-forecast.php script to Version 3.x. Since WeatherUnderground no longer includes forecast JSON data in the page, the V3.x script uses the WU API to get the forecast data for the script. To use it, you must acquire an API Key at http://www.wunderground.com/weather/api/ .

I thought it was a good idea to make WU forecast output available in multiple languages (since the WU site supports translations). I wrote the WU-forecast.php to create a carterlake-style forecast output that would use the saratoga (NOAA) icon set (or the WU Icon set), would be easy to include in a weather website, and have built-in support for translations to other languages based on those languages provided by WeatherUnderground.

Unlike the carterlake/NOAA forecast script which reads the public domain NWS websites, this script reads and processes the WU API JSON feed from WeatherUnderground.com, which contains copyrighted material. WU has a very stringent (and somewhat strident) Terms of Use that on first reading seems to prohibit any usage of their site, even by personal, non-commercial websites who’s owners are contributing their weather data to Weather Underground. The ToS seems to prohibit even the common usage by VWS templates (and my AJAXed versions) which make extensive use of WU forecast, graphics and data in their design.

Be sure to include the trailing slash in the directory specification as shown in the example above. Saratoga template users: Use the Settings.php entry for $SITE[‘fcsticonsdir’] to specify this value. $iconType This setting controls the extension (type) for the icon to be displayed. =’.jpg’; for the default Saratoga JPG icon set. =’.gif’; for the Meteotriviglio animated GIF icon set. Saratoga template users: Use the Settings.php entry for $SITE[‘fcsticonstype’] to specify this value. $WU_URL This is the full URL for the WeatherUnderground page containing the forecast. Find it by searching on WU for a nearby city to your weather station location. Copy the full URL from your browser address bar to the area between the single quotes. Please note that some WU translations may be incomplete as not all words/phrases may be translated from English. Also note that changing from English may involve using different character sets than the ISO-8859-1 Latin set. The script will produce HTML with a tag specifying the character set — if you include the script in a page, make sure the including page uses the character set of the WU page otherwise your output page may be garbled and unreadable. Saratoga template users: Use the Settings.php entry for $SITE[‘fcsturlWU’] to specify this value. $WUforecasts = array(

); This setting is an alternative method of specifying the locations for forecasts. If used, it will override the main location specified in the $WU_URL above and allow the viewer to choose between forecasts for different areas based on a drop-down list box selection. Saratoga template users: Use the Settings.php entry for $SITE[‘WUforecasts’] = array(…); to specify the list of sites and URLs. $maxWidth This variable controls the maximum width of the tables for the icons and text display. It may be in pixels (as shown), or ‘100%’. The Saratoga/NOAA icons are 55px wide and there are up to 14 icons, so beware setting this width too small as the display may be quite strange. $maxIcons This variable specifies the maximum number of icons to display in the graphical part of the forecast. Some forecast locations may have up to 7 days of forecast (14 icons) so be careful how wide the forecast may become on the page. $cacheFileDir This setting specifies the directory to store the cache files. The default is the same directory in which the script is located.

Saratoga template users: Use the Settings.php entry for $SITE[‘cacheFileDir’] to specify this value. $cacheName This variable specifies the name of the cache file for the WU forecast page. $refetchSeconds This variable specifies the cache lifetime, or how long to use the cache before reloading a copy from Weather Underground. The default is 3600 seconds (60 minutes). Forecasts don’t change very often, so please don’t reduce it below 60 minutes to minimize your API access count and keep it to the free Developer API range. $xlateCOP This setting is used to replace the phrase ‘Chance of precipitation’ with the same phrase in your language. Currently, Wunderground doesn’t have this phrase translated in the non-English websites Saratoga template users: Use the Settings.php entry for $SITE[‘xlateCOP’] to specify this value. $showTempsAs This setting controls how the temperatures are displayed below the condition icons.