NWS forecast.weather.gov changing 7-Mar-2017. New advforecast2.php V5.00

The announced changover date for forecast.weather.gov is still 7-Mar-2017 and it has a lot of changes. The forecast-v3.weather.gov site (preview NWS site) shows what the new site will look like.

For we who operate personal weather websites that use my advforecast2.php script, be aware that the coming changes will make V4.x of the script NO LONGER WORK as they have removed the /MapClick.php?.. functionality of the forecast.weather.gov website in favor of a new request mechanism.

I’ve put together advforecast2.php V5.00 as a fairly complete rewrite of the prior script. It now uses the api.weather.gov website to retrieve JSON data for point-forecasts, zone forecasts and the needed metadata about both.
I’m not going to release the update via my usual channels (script page and Saratoga template Updates tool) until AFTER their cutover is done, but… you can make your USA website ready by installing the contents of the attached zip file.

Here’s the README file included with the .zip file that helps explain what’s changed:

This is the updated support package for version of advforecast2.php V5.00 - 06-Mar-2017

The advforecast2.php V5.00 uses the new NWS api.forecast.gov to retrieve JSON data and construct the forecast
display, so it differs from all prior versions (which used page scraping of the point-printable
forecast).

Since the new forecast.weather.gov website uses a different method to specify the point forecast,
the script includes auto-conversion of old-format point-printable forecast URLs to the new
format required.

As of 6-Mar-2017, the api.weather.gov alerts query returns only alerts of types: 
Advisory, Watch, Warning and Statement.
The Outlook type alert is NOT currently included in the feed.
That may change in the future, but be aware that "Hazardous Weather Outlook" will not be displayed.

New with this release:

Improved diagnostics (available with ?debug=y on the URL) as HTML comments on the page
Improved cURL-based fetch for all data from api.weather.gov

cache files for the script have new (but related) names:
./cache/forecast-{Zone}-{n}-json.txt  contains the forecast data for the point or Zone
./cache/forecast-{Zone}-{n}-json-alerts.txt  contains the alert data for the Zone
./cache/forecast-{Zone}-{n}-json-meta.txt  contains the metadata about the point, Zone and WFO

New icon template file:
./forecast/icon-templates/nsmoke.png   (nighttime smoke image)

New icons with PoP stamps:
./forecast/images/cold[0..100].[jpg|png]  daytime cold w/PoP stamps
./forecast/images/ncold[0..100].[jpg|png] nighttime cold w/PoP stamps

DualImage.php V1.01 - 06-Mar-2017 supports the modified/new icon names from the NWS

advforecast2.php V5.00 - 06-Mar-2017 has additional new features:

setting addition:
$showTwoIconRows = true;   // =true; show all icons, =false; show 9 icons in one row (new V5.00)

If =true;, then two rows of up-to 9 columns of icons for day and night icons are shown
If =false;, then the original style of one row of 9 icons are shown.

running advforecast2.php?convert will display the the converted new-format point forecast URLs and
other settings needed.  If run on a site with a Saratoga template, the $SITE[] settings for Settings.php
will display, otherwise, the internal settings needed for advforecast2.php itself will be displayed.

Samples:
----------original settings----------
$NWSforecasts = array(
 // the entries below are for testing use.. replace them with your own entries if using the script
 // outside the AJAX/PHP templates.
 // ZONE|Location|point-forecast-URL  (separated by | characters
"CAZ513|Saratoga, CA (WRH)|http://forecast.weather.gov/MapClick.php?CityName=Saratoga&state=CA&site=MTR&textField1=37.2639&textField2=-122.022&e=1&TextType=2",
"NEZ052|Omaha, NE (CRH)|http://forecast.weather.gov/MapClick.php?lat=41.2586&lon=-95.9378&unit=0&lg=english&FcstType=text&TextType=2",
"ALZ266|Gulf Shores, AL (SRH)|http://forecast.weather.gov/MapClick.php?CityName=Gulf+Shores&state=AL&site=MOB&textField1=30.27&textField2=-87.7015&e=0&TextType=2",
'MDZ022|Salisbury, MD (ERH)|http://forecast.weather.gov/MapClick.php?lat=38.36818&lon=-75.59761&unit=0&lg=english&FcstType=text&TextType=2',
'AKZ101|Anchorage, AK (ARH)|http://forecast.weather.gov/MapClick.php?lat=61.21806&lon=-149.90027780000003&unit=0&lg=english&FcstType=text&TextType=2',
'HIZ005|Honolulu, HI (HRH)|http://forecast.weather.gov/MapClick.php?lat=21.30694&lon=-157.85833330000003&unit=0&lg=english&FcstType=text&TextType=2',
'IAZ068|Riverdale, IA|http://forecast.weather.gov/MapClick.php?lat=41.5354&lon=-90.4671&unit=0&lg=english&FcstType=text&TextType=2',
'MEZ030|Bar Harbor, ME|http://forecast.weather.gov/MapClick.php?lat=44.76&lon=-67.5477&unit=0&lg=english&FcstType=text&TextType=2',
'TXZ147|Fairfield, TX|http://forecast.weather.gov/MapClick.php?&lat=31.7188&lon=-96.1655&lg=english&FcstType=text&TextType=2',
'SDZ021|Millbank, SD|http://forecast.weather.gov/MapClick.php?lat=45.194&lon=-96.6869&unit=0&lg=english&FcstType=text&TextType=2',
'MNZ034|Brainerd, MN|http://forecast.weather.gov/MapClick.php?lat=46.3544&lon=-94.1941&unit=0&lg=english&FcstType=text&TextType=2',
'COZ010|Vail, CO|http://forecast.weather.gov/MapClick.php?lat=39.5864&lon=-106.3822&unit=0&lg=english&FcstType=text&TextType=2',
'CAZ072|South Lake Tahoe, CA|http://forecast.weather.gov/MapClick.php?lat=38.93333&lon=-119.98333&unit=0&lg=english&FcstType=text&TextType=2',
'WAZ037|Colville, WA|http://forecast.weather.gov/MapClick.php?lat=48.5433&lon=-117.8951&unit=0&lg=english&FcstType=text&TextType=2',
'ILZ014|Hoffman Estates, IL|http://forecast.weather.gov/MapClick.php?lat=42.03921&lon=-88.11001&unit=0&lg=english&FcstType=text&TextType=2',
'NDZ027|Grand Forks,  ND|http://forecast.weather.gov/MapClick.php?lat=47.9169&lon=-97.072&unit=0&lg=english&FcstType=text&TextType=2',
'MTZ055|Bozeman, MT|http://forecast.weather.gov/MapClick.php?lat=45.6354&lon=-111.0633&unit=0&lg=english&FcstType=text&TextType=2',
"AZZ023|Phoenix|http://forecast.weather.gov/MapClick.php?CityName=Phoenix&state=AZ&site=PSR&textField1=33.646&textField2=-112.007&e=0&TextType=2",
'KSZ078|Dodge City, KS|http://forecast.weather.gov/MapClick.php?lat=37.7528&lon=-100.0171&unit=0&lg=english&FcstType=text&TextType=2',
'OKZ020|Stillwater, OK|http://forecast.weather.gov/MapClick.php?lat=36.1156&lon=-97.0584&unit=0&lg=english&FcstType=text&TextType=2',
); 
//*/
//*
//
 $NOAAZone = 'CAZ513';  // change this line to your NOAA warning zone.
// set $fileName to the URL for the point-printable forecast for your area
// NOTE: this value (and $NOAAZone) will be overridden by the first entry in $NWSforecasts if it exists.
 $fileName = "http://forecast.weather.gov/MapClick.php?CityName=Saratoga&state=CA&site=MTR&textField1=37.2639&textField2=-122.022&e=1&TextType=2";
//*/
$showTwoIconRows = true;   // =true; show all icons, =false; show 9 icons in one row (new V5.00)

-------------------------------------

-----Converted settings for standalone ------
// advforecast2.php (JSON) - V5.00 - 06-Mar-2017 
// settings converted to new point-forecast request URLs.
// Put these in advforecast2.php to update the settings there.

// -- start of converted settings for advforecast2.php JSON version.
$NWSforecasts = array(
// the entries below are for testing use.. replace them with your own entries if using the script
// outside the Saratoga AJAX/PHP templates.
// ZONE|Location|point-forecast-URL  (separated by | characters
 'CAZ513|Saratoga, CA (WRH)|https://forecast-v3.weather.gov/point/37.2639,-122.022',
 'NEZ052|Omaha, NE (CRH)|https://forecast-v3.weather.gov/point/41.2586,-95.9378',
 'ALZ266|Gulf Shores, AL (SRH)|https://forecast-v3.weather.gov/point/30.27,-87.7015',
 'MDZ022|Salisbury, MD (ERH)|https://forecast-v3.weather.gov/point/38.3682,-75.5976',
 'AKZ101|Anchorage, AK (ARH)|https://forecast-v3.weather.gov/point/61.2181,-149.9003',
 'HIZ005|Honolulu, HI (HRH)|https://forecast-v3.weather.gov/point/21.3069,-157.8583',
 'IAZ068|Riverdale, IA|https://forecast-v3.weather.gov/point/41.5354,-90.4671',
 'MEZ030|Bar Harbor, ME|https://forecast-v3.weather.gov/point/44.76,-67.5477',
 'TXZ147|Fairfield, TX|https://forecast-v3.weather.gov/point/31.7188,-96.1655',
 'SDZ021|Millbank, SD|https://forecast-v3.weather.gov/point/45.194,-96.6869',
 'MNZ034|Brainerd, MN|https://forecast-v3.weather.gov/point/46.3544,-94.1941',
 'COZ010|Vail, CO|https://forecast-v3.weather.gov/point/39.5864,-106.3822',
 'CAZ072|South Lake Tahoe, CA|https://forecast-v3.weather.gov/point/38.9333,-119.9833',
 'WAZ037|Colville, WA|https://forecast-v3.weather.gov/point/48.5433,-117.8951',
 'ILZ014|Hoffman Estates, IL|https://forecast-v3.weather.gov/point/42.0392,-88.11',
 'NDZ027|Grand Forks,  ND|https://forecast-v3.weather.gov/point/47.9169,-97.072',
 'MTZ055|Bozeman, MT|https://forecast-v3.weather.gov/point/45.6354,-111.0633',
 'AZZ023|Phoenix|https://forecast-v3.weather.gov/point/33.646,-112.007',
 'KSZ078|Dodge City, KS|https://forecast-v3.weather.gov/point/37.7528,-100.0171',
 'OKZ020|Stillwater, OK|https://forecast-v3.weather.gov/point/36.1156,-97.0584',

);
//
$NOAAZone = 'CAZ513'; // change this line to your NOAA warning zone.
//
// set $fileName  to the URL for the point-printable forecast for your area
// NOTE: this value (and $NOAAZone) will be overridden by the first entry in $NWSforecasts if it exists.
//
$fileName = 'https://forecast-v3.weather.gov/point/37.2639,-122.022';
//
$showTwoIconRows = true;   // =true; show all icons, =false; show 9 icons in one row (new V5.00)
//
// -- end of converted settings for advforecast2.php JSON version.
-------------------------------------

-----Converted settings for Saratoga template ------
// advforecast2.php (JSON) - V5.00 - 06-Mar-2017 
// settings converted to new point-forecast request URLs.
// Put these in Settings.php to update the settings there.

// -- start of converted settings for advforecast2.php JSON version.
$SITE['NWSforecasts'] = array(
// the entries below are for testing use.. replace them with your own entries if using the script
// outside the Saratoga AJAX/PHP templates.
// ZONE|Location|point-forecast-URL  (separated by | characters
 'CAZ513|Saratoga, CA (WRH)|https://forecast-v3.weather.gov/point/37.2639,-122.022',
 'NEZ052|Omaha, NE (CRH)|https://forecast-v3.weather.gov/point/41.2586,-95.9378',
 'ALZ266|Gulf Shores, AL (SRH)|https://forecast-v3.weather.gov/point/30.27,-87.7015',
 'MDZ022|Salisbury, MD (ERH)|https://forecast-v3.weather.gov/point/38.3682,-75.5976',
 'AKZ101|Anchorage, AK (ARH)|https://forecast-v3.weather.gov/point/61.2181,-149.9003',
 'HIZ005|Honolulu, HI (HRH)|https://forecast-v3.weather.gov/point/21.3069,-157.8583',
 'IAZ068|Riverdale, IA|https://forecast-v3.weather.gov/point/41.5354,-90.4671',
 'MEZ030|Bar Harbor, ME|https://forecast-v3.weather.gov/point/44.76,-67.5477',
 'TXZ147|Fairfield, TX|https://forecast-v3.weather.gov/point/31.7188,-96.1655',
 'SDZ021|Millbank, SD|https://forecast-v3.weather.gov/point/45.194,-96.6869',
 'MNZ034|Brainerd, MN|https://forecast-v3.weather.gov/point/46.3544,-94.1941',
 'COZ010|Vail, CO|https://forecast-v3.weather.gov/point/39.5864,-106.3822',
 'CAZ072|South Lake Tahoe, CA|https://forecast-v3.weather.gov/point/38.9333,-119.9833',
 'WAZ037|Colville, WA|https://forecast-v3.weather.gov/point/48.5433,-117.8951',
 'ILZ014|Hoffman Estates, IL|https://forecast-v3.weather.gov/point/42.0392,-88.11',
 'NDZ027|Grand Forks,  ND|https://forecast-v3.weather.gov/point/47.9169,-97.072',
 'MTZ055|Bozeman, MT|https://forecast-v3.weather.gov/point/45.6354,-111.0633',
 'AZZ023|Phoenix|https://forecast-v3.weather.gov/point/33.646,-112.007',
 'KSZ078|Dodge City, KS|https://forecast-v3.weather.gov/point/37.7528,-100.0171',
 'OKZ020|Stillwater, OK|https://forecast-v3.weather.gov/point/36.1156,-97.0584',

);
//
$SITE['noaazone'] = 'CAZ513'; // change this line to your NOAA warning zone.
//
// set $SITE['fcsturlNWS']  to the URL for the point-printable forecast for your area
// NOTE: this value (and $SITE['noaazone']) will be overridden by the first entry in $SITE['NWSforecasts'] if it exists.
//
$SITE['fcsturlNWS'] = 'https://forecast-v3.weather.gov/point/37.2639,-122.022';
//
$SITE['showTwoIconRows'] = true;   // =true; show all icons, =false; show 9 icons in one row (new V5.00)
//
// -- end of converted settings for advforecast2.php JSON version.
-------------------------------------

I’m sure there will be additional updates as the new forecast.weather.gov settles in.

My thanks to the brave beta testers of the advforecast-json.php script! That script is now named advforecast2.php for backward compatibility reasons.

Best regards,
Ken


advforecast2-V5.00.zip (122 KB)

Thanks for the update Ken. Works perfect.

Today (7 Mar) was the planned NWS release date, but they have now pushed that to 14 Mar. See http://www.wxforum.net/index.php?topic=31623.0 for more info on some items that are now ‘working’ and some not.

Does the new version have big changes from the beta? I don’t need a list, just curious.

niko, technically it’s still beta. Ken’s first post above shows his read me listing what’s new in this version.

Ah, I thought those were the changes vs. the non-json version. I’m already running the beta and was mentally preparing myself to switch to this version.

Yes, a few. The regex for extracting lat/long from the NEW point/lat,long/forecast was corrected to work now.
The whole ?convert option was added to show what your current settings should be for standalone or template users.

Those are the two big changes from the prior beta.

Thanks Ken, I’ll see if I can get into trouble :slight_smile:

Now the NWS preview site says

Notice of NWS’ New Version of Forecast
A new version of Forecast will launch April 4, 2017.

So… we have more time before we must implement the new JSON advforecast2.php. On the WXforum.net thread there’s been discussion about rogue ‘Wind chill…’ and ‘Heat index…’ appearing in the text, and some changes in the location info available via the API. Guess they’re still tweaking the code in both the api.weather.gov and forecast-v3.weather.gov.

Meanwhile, I’m not going to ‘push’ the code to the standalone/template users until I see the actual implementation of forecast.weather.gov done… I’ll just get ready to release the final code on their day of implementation.

Is it ok to leave the newer version on our systems? It seems to be working ok from what I can tell but thought I should ask…

Does anyone know if the api has been disabled at this point? I have been using it for the past couple of weeks. However, starting this morning, I receive a 503 error when trying with https://api.weather.gov/points/33.9532,-117.6964/forecast

–Steve

I’ve seen that from time to time for the last several days at least, at the moment my forecast is unavailable too.

The updated script (above) responds with a Zone forecast if the point forecast request gives a 503 response. That seems to be the same failover the forecast-v3.weather.gov site uses when the point forecast isn’t ready.

Using https://forecast-v3.weather.gov/point/33.9532,-117.6964 as the query results in

Zone Data Notice

Current weather data was not available for the location you requested. The zone data will be displayed until your location has been refreshed.

and the text-only version of the forecast for the forecast Zone is displayed.

Like the prior advforecast2.php, the Zone forecast text is parsed and icons assigned based on the wording of each forecast text entry. The temperature area then displays symbols before the temperature to indicate these are approximate numbers based on the text description of the temperature range.

When the point forecast is again available, the script will automatically switch to using it instead of the zone forecast.

Sure, but be aware that the forecast text may have unexpected entries (like the “Heat index…” and “Wind-Chill…” specious text strings that appeared on some forecasts today). If it’s accuracy you want, I’d stick to the current advforecast2.php V4.02 which uses the production forecast.weather.gov.

If you don’t mind some variants from time to time, use the V5.00 JSON version. The forecasts use the same GFS data, but just use different text-construction engines, and they’re still tweaking that on their preview site.

Understand this all still beta…just wondering why none of my locations other than the default forecast are working. Using the drop down menu only the first entry in the list works, all the others show an error. Near as I can tell the forecasts are available when I use my browser to view, but the script continues to report an error. I know my other locations were working a few days ago, so I assume the problem is with the NWS making changes…just wanted to mention it…it’s possible you have published a newer version of the new script that handles changes the NWS has made but aren’t addressed in the version of the script I am running.

Uh oh, I have 86x86 .png regular icons, and 55x55 .jpg dual icons. I don’t think I had that issue with the old version. Can the dual icons be .png, and where is the size set?

Yes, change DualImage.php to have ‘png’ as the type, and it will auto-size accordingly to 86x86 dual icons.

OK, thanks. That fixed the size :slight_smile: I have na.png for Sunday but my NWS forecast has an error so not much I can do about that at the moment :frowning:

Both forecast-v3.weather.gov and api.weather.gov have been unstable for several days… it’s catch as catch can. I’m guessing they are trying to prep their infrastructure for the intended launch on April 4th (optimistic IMHO, but still possible).

If you want conditions displayed now on your site, I’d use the V4.02 advforecast2.php script and use the JSON script only for testing. It’s what I’ve recommended on the WXForum.net thread also.

Hi Ken. I am trying this out, thanks.

I have a little suggestion. It is generally now best practice to leave out the closing PHP tag ?> at the end of any PHP script. It helps eliminate the possibility of white space being added by editors after the closing tag that can cause issues interfering with sessions and “headers already sent” errors. I even remember seeing these kind of issues here before with other scripts. I stopped using the closing PHP tags in my WordPress plugins a couple years ago and never get these errors anymore. You probably don’t have to go update any script because of this, but while doing other updates, go ahead and do this at the same time.

I like to put this: where ?> would have been
// end of file

Thanks, Mike