deformed-offering

Weather station scripts - NWS Forecast

They're free, but use at your own risk

The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

Many of these scripts are now available on GitHub at https://github.com/ktrue

Buy Me A Coffee If you find one or more of the scripts useful to you, please consider making a donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on WXForum.net and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

Note: Twitter widget has been disabled 3-Jul-2023 since it no longer displays the recent update Tweets.

This page was updated Wednesday, 14-Aug-2024 7:40 AM

Carterlake.org scripts with a few mods...

Tom at carterlake.org has done a great job generating and freely sharing his PHP scripts for other sites to use. I started my own journey with PHP programming by using his scripts (and Larry's at Anole Computer) as learning examples, and I can't thank them enough for their sharing! With Tom's permission (and some encouragement), I've set up this page to have links to the carterlake scripts that I've modified for various puposes. Most of the mods have to do with formatting for XHTML 1.0-Strict output (even when the source page was not).

advforecast.php (NOAA Forecast for all NWS areas)

Note: as of 12-Mar-2007, the Western Region website (www.wrh.noaa.gov) now offers the point-printable forecasts in the same format as the other regional websites, so this script now works for WRH, ERH, SRH and CRH websites.

Tom's advforecast.php script takes the point-printable forecast from NOAA for Western, Eastern, Southern and Central region NOAA websites, and converts to a set of icons/conditions/temperatures and text forecast for inclusion on your webpage. My mods add XHTML 1.0-Strict output and the ability to handle a redirection for county forecasts (offered by www.crh.noaa.gov) in case a point-printable forecast is not available. See these threads for the erh2crh version (http://www.wxforum.net/viewtopic.php?p=3768, and http://www.weather-watch.com/smf/index.php/topic,22504.0.html ) The latest version of this script also offers automatic failover to the Zone forecast if the point-printable forecast is not available. Set "$NOAAZone = 'ssZnnn';" in the code for your NOAA warning zone.

The script supports the ?force=1 parameter to reload the cache file, and also a ?force=2 to load the cache file from the backup County Zone forecast.

To use, you'll need an icon set uploaded in the /forecast/images directory on your website, and to set the $fileName variable inside the script to the URL for the point-printable forecast.

With V2.06 and up, the new parsing of the failover Zone forecast requires additional icons (available below) to be placed on your website.

In July, 2015, the NOAA-NWS updated the icon set and provided a new dual-image icon to display 6-hour conditions for the 12-hour forecast icon. This icon is dynamically generated by a DualImage.php script (available below in the UPDATES file). With the DualImage.php script and associated icon templates installed, the V4.00+ version of advforecast2.php will support dynamic generation of dual images when needed. The script will fall-back to showing just the first 6-hour image if the DualImage.php is not available, OR if the meteotriviglio animated GIF images are used.

In June, 2017, the NWS forecast.weather.gov website had planned a major renovation and would deprecate the use of /MapClick.php?lat={latitude}&lon={longitude} for finding the weather at your location. V5.00 of advforecast2.php now uses the new api.weather.gov JSON feeds to generate the icons/forecast text as the V4.x and prior scripts would have no longer worked via page-scraping.
That conversion by NWS is on indefinite hold so either version V4.0x or V5.0x will work on your site at this time.

Also new with the V5.x script is the number of icons available rose from 9 to 14 and the option to display the old-format 9 icons or the new format with two rows of (up-to) 8 icons is controlled by one switch variable ($showTwoIconRows in the script, or $SITE['showTwoIconRows'] in Settings.php).

On February 27, 2018, the NWS switched forecast.weather.gov to HTTPS only, so advforecast2.php V4.02 and earlier will not work as those versions supported only HTTP access. The advforecast2.php V4.03 was released to handle HTTPS access and should be the last release of the venerable page-scraper script. Please note that the Version 5.x script uses the beta api.weather.gov JSON feed and already used HTTPS only.
The V5.09 script is included in the Base-USA Saratoga template. For those not wanting to use the beta code, you can download the V4.05 script below and use with your template. Both V4.05 and V5.x versions will continue to have support while the api.weather.gov is still in beta test.

Note: to use either 4.0x or 5.0x version of the script, it is important to continue using the point-printable version of the URL for your location based on the current https://www.weather.gov/ website. Your links should resemble:

https://forecast.weather.gov/MapClick.php?lat=nn.nnnn&lon=-nnn.nnnn&unit=0&lg=english&FcstType=text&TextType=2

with the &unit=0&lg=english&FcstType=text&TextType=2 at the end after the lat= and lon= arguments.

Tip: use NWS-info-map to quickly locate your desired forecast points and get copycode to put in the $NWSforecasts array.

Sample code

Sample included with:

<?php
$doIncludeNWS = true;
include("advforecast2.php"); ?>

will show

National Weather Service Forecast for: Saratoga, CA
Issued by: National Weather Service San Francisco Bay Area/Monterey, CA
Updated: Fri, 13-Dec-2024 3:35am PST

Saratoga
 
Today

Today: Chance Light Rain
Chance Light Rain
Saturday

Saturday: Rain
Rain
Sunday

Sunday: Patchy Fog then Sunny
Patchy Fog then Sunny
Monday

Monday: Light Rain
Light Rain
Tuesday

Tuesday: Mostly Sunny
Mostly Sunny
Wednesday

Wednesday: Sunny
Sunny
Thursday

Thursday: Mostly Sunny
Mostly Sunny
 
Hi 59 °F Hi 59 °F Hi 59 °F Hi 57 °F Hi 60 °F Hi 65 °F Hi 67 °F  
 
Tonight

Tonight: Rain
Rain
Saturday
Night
Saturday Night: Partly Cloudy then Patchy Fog
Partly Cloudy then Patchy Fog
Sunday
Night
Sunday Night: Mostly Cloudy then Chance Light Rain
Mostly Cloudy then Chance Light Rain
Monday
Night
Monday Night: Chance Light Rain
Chance Light Rain
Tuesday
Night
Tuesday Night: Mostly Clear
Mostly Clear
Wednesday
Night
Wednesday Night: Mostly Clear
Mostly Clear
Thursday
Night
Thursday Night: Partly Cloudy
Partly Cloudy
 
Lo 49 °F Lo 38 °F Lo 41 °F Lo 42 °F Lo 40 °F Lo 43 °F Lo 45 °F  

Wind Advisory
 

Today
 
A chance of rain. Mostly cloudy. High near 59, with temperatures falling to around 55 in the afternoon. South southeast wind 9 to 13 mph, with gusts as high as 35 mph. Chance of precipitation is 40%. New rainfall amounts less than a tenth of an inch possible.
Tonight
 
Rain. Cloudy, with a low around 49. South southeast wind 10 to 28 mph, with gusts as high as 55 mph. Chance of precipitation is 100%. New rainfall amounts between three quarters and one inch possible.
Saturday
 
Rain before 4pm. Mostly cloudy. High near 59, with temperatures falling to around 53 in the afternoon. West southwest wind 6 to 21 mph, with gusts as high as 48 mph. Chance of precipitation is 100%. New rainfall amounts between a half and three quarters of an inch possible.
Saturday Night
 
Patchy fog after 3am. Partly cloudy, with a low around 38. Northwest wind 2 to 6 mph.
Sunday
 
Patchy fog before 9am. Sunny, with a high near 59. North northeast wind around 3 mph.
Sunday Night
 
A chance of rain after 4am. Mostly cloudy, with a low around 41. Chance of precipitation is 50%. New rainfall amounts between a tenth and quarter of an inch possible.
Monday
 
Rain. Mostly cloudy, with a high near 57. Chance of precipitation is 80%.
Monday Night
 
A chance of rain before 4am. Mostly cloudy, with a low around 42.
Tuesday
 
Mostly sunny, with a high near 60.
Tuesday Night
 
Mostly clear, with a low around 40.
Wednesday
 
Sunny, with a high near 65.
Wednesday Night
 
Mostly clear, with a low around 43.
Thursday
 
Mostly sunny, with a high near 67.
Thursday Night
 
Partly cloudy, with a low around 45.

 

Forecast from NOAA-NWS for Saratoga, CA.

You can also include it 'silently' and print just a few (or all) the contents where you'd like it on the page

<?php
$doPrintNWS = false;
require("advforecast2.php"); ?>

then on your page, the following code would display just the current and next time period forecast:

 <table>
<tr align="center" valign="top">
<?php print "<td>$forecasticons[0]</td><td>$forecasticons[1]</td>\n"; ?>
</tr>
<tr align="center" valign="top">
<?php print "<td>$forecasttemp[0]</td><td>$forecasttemp[1]</td>\n"; ?>
</tr>
</table>
Today

Today: Chance Light Rain
Chance Light Rain
Tonight

Tonight: Rain
Rain
Hi 59 °FLo 49 °F

Or if you'd like to include the immediate forecast with text for the next two cycles:

<table>
<tr valign="top">
<?php print "<td align=\"center\">$forecasticons[0]<br />$forecasttemp[0]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$forecasttext[0]</td>\n"; ?>
</tr>
<tr valign="top">
<?php print "<td align=\"center\">$forecasticons[1]<br />$forecasttemp[1]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$forecasttext[1]</td>\n"; ?>
</tr>
</table>

Today

Today: Chance Light Rain
Chance Light Rain

Hi 59 °F
A chance of rain. Mostly cloudy. High near 59, with temperatures falling to around 55 in the afternoon. South southeast wind 9 to 13 mph, with gusts as high as 35 mph. Chance of precipitation is 40%. New rainfall amounts less than a tenth of an inch possible.
Tonight

Tonight: Rain
Rain

Lo 49 °F
Rain. Cloudy, with a low around 49. South southeast wind 10 to 28 mph, with gusts as high as 55 mph. Chance of precipitation is 100%. New rainfall amounts between three quarters and one inch possible.

Download: advforecast2.php (V5.19 - 27-Dec-2022) JSON version uses the api.weather.gov site, also included in the USA template.
Download: advforecast2.php (V4.06 -30-Apr-2024) older version for those not wanting to experiment with the api.weather.gov beta site
Download: Icon Set (V2 for NWS 55x55 icons) (upload to your website in the /forecast/images directory)
Download: Icon Set UPDATES July-2015 and DualImage.php script
Download: Icon Set UPDATES April-2017 and DualImage.php script(upload to your website and preserve the directory names - included with Base-USA template)
Download: DualImage.php (V1.04 - 06-Apr-2022) - included with Base-USA template and icon sets above.

deformed-offering