WXforum.net
Web Weather => Weather Website PHP/AJAX scripting => Topic started by: saratogaWX on April 30, 2019, 02:37:47 PM
-
With the announcement of the NWS (https://www.weather.gov/media/notification/scn19-35forecast-gridpoint.pdf) on 29-Apr-2019 that the api.weather.gov was deprecating the forecast queries for points/ and removing the current 302 redirect to a gridpoint forecast, the underlying method of using the API had to change in the script.
Now, the specified point's meta-data is fetched first (from cache if available, otherwise fetched from API and cached) and the gridpoint forecast is used directly (based on the meta-data content). The prior caching method (in ./cache/forecast-URLcache.txt) is no longer used (that had contained the point->gridpoint URLs).
Now the ./cache/forecast-{zone}-{N}-json-meta.txt file contains all the relevant data about the specified point that was derived from multiple API fetches re: point, Zone, WFO and saved.
If you're using the V5.10 script, please update before 24-Jun-2019 when the NWS will turn off the 302 redirect for the point forecast and that version of the script will likely fail to work properly.
Standalone update: use the script page (https://saratoga-weather.org/scripts-carterlake.php#advforecast) for download.
Saratoga Template(USA): use the update tool (https://saratoga-weather.org/wxtemplates/updates.php) page with query Base-USA, Plugin-*, 30-Apr-2019
-
All over my head, but once again a big thank you Ken.
-
I can understand 9 words in that post. Billy Madison
https://getyarn.io/yarn-clip/embed/1d44f626-ae87-46fa-9174-f3e55d76dc18?autoplay=false
-
Thanks Ken.
-
Yep, thanks Ken. [tup]
-
Thanks, Ken!
The hourly stuff is for future use if the comments are accurate. :grin: Want any of us to turn the fetch on just to make sure it all does what it's supposed to?
-
You're free to turn it on if you like (it will fetch/store the hourly data in a separate cache file). I just haven't added the display code to the script. Thought I'd do something like the tabbed display for daily/hourly that I do with the DarkSky script (DS-forecast.php), or maybe a meteogram-like display using HighCharts. The data is in the API.. just thought it should be handled at some time.
The only cost to turning it on is one extra fetch of (fairly large) JSON from api.weather.gov which could add a couple of seconds to the page load time (since the page will wait while data is being fetched).
-
All over my head, but once again a big thank you Ken.
I can understand 9 words in that post. Billy Madison
https://getyarn.io/yarn-clip/embed/1d44f626-ae87-46fa-9174-f3e55d76dc18?autoplay=false
Sorry folks, I didn't mean to confuse -- just wanted to document the internal changes and 'why' so others (who may want to develop their own scripts) could see what the API changes might mean to their script's logic flow. It does read a bit like a StackOverflow answer to a detailed question :shock: 8-)
-
The only cost to turning it on is one extra fetch of (fairly large) JSON from api.weather.gov which could add a couple of seconds to the page load time (since the page will wait while data is being fetched).
I pull the forecast in a cron job so that it doesn't affect the page load, so that's the only place I'll take the hit. I'll turn it on in my sandbox just to give it some airtime.
-
All over my head, but once again a big thank you Ken.
I can understand 9 words in that post. Billy Madison
https://getyarn.io/yarn-clip/embed/1d44f626-ae87-46fa-9174-f3e55d76dc18?autoplay=false
Sorry folks, I didn't mean to confuse -- just wanted to document the internal changes and 'why' so others (who may want to develop their own scripts) could see what the API changes might mean to their script's logic flow. It does read a bit like a StackOverflow answer to a detailed question :shock: 8-)
I just take your word that all is good. Blindly follow.
It is on this page https://rms-weather.rdale.org/testpage/weather.php
-
Thanks for the update, Ken. I'd be lost without you!
-
Thought I'd do something like the tabbed display for daily/hourly that I do with the DarkSky script (DS-forecast.php), or maybe a meteogram-like display using HighCharts. The data is in the API.. just thought it should be handled at some time.
Can you point me to implementation examples? I'm trying to envision this. Tabbing seems reasonable.
FWIW I find "hourly" granularity beyond 36 hours or so to be pretty useless (like 10-day forecasts). Good thing the NWS gives us 150+ hours. :grin:
-
Sure, my DS-forecast demo (https://saratoga-weather.org/DS-forecast-demo.php) page shows one method of tabbed display. Script is here (https://saratoga-weather.org/scripts-DSforecast.php) on the scripts page.
I don't have a sample of the intended meteogram graphs, but the version on the NWS beta forecast-v3.weather.gov site (https://forecast-v3.weather.gov/point/37.2711,-122.014/charts?tab=hwg) shows what might be done.
-
I am having an issue with the NOAA-NWS 2nd page. When I click the link, I get:
"{
"@context": [
"https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
{
"wx": "https://api.weather.gov/ontology#",
"geo": "http://www.opengis.net/ont/geosparql#",
"unit": "http://codes.wmo.int/common/unit/",
"@vocab": "https://api.weather.gov/ontology#"
}
],
and it goes down a ways, but you can read the forecast... The URL in the address bar is shown as : "https://api.weather.gov/gridpoints/GYX/22,77/forecast
Prior to this version, is was working fine.
Gary
-
Yeah, that link should be of the form:
https://forecast-v3.weather.gov/point/latitude,longitude
rather than the API gridpoints URL.
Should be an easy fix for Ken.
-
Ah.. my bad. I've now updated to 5.12 with the corrected link to weather.gov pages for both point and zone forecasts.
-
Thanks Ken... [tup]
-
Ah.. my bad. I've now updated to 5.12 with the corrected link to weather.gov pages for both point and zone forecasts.
*Sigh*
Sorry, but must be feeling lazy today after spending 4 hours yesterday finding the appropriate lines for adapting the stand-alone page script layout to my preferences....
I know I'm in the minority by using a stand-alone page (that has background and other layout modifications) but if there is only a line or two of change it would be a lot easier to change the altered line(s) than replace the whole page and then have to go back and change many lines of layout code.
If that is the case, only a line or two change, would it be possible to just post the changed lines? They are usually easy to find by doing a "Search" for line(s) to be changed.
-
Ah.. my bad. I've now updated to 5.12 with the corrected link to weather.gov pages for both point and zone forecasts.
*Sigh*
Sorry, but must be feeling lazy today after spending 4 hours yesterday finding the appropriate lines for adapting the stand-alone page script layout to my preferences....
I know I'm in the minority by using a stand-alone page (that has background and other layout modifications) but if there is only a line or two of change it would be a lot easier to change the altered line(s) than replace the whole page and then have to go back and change many lines of layout code.
If that is the case, only a line or two change, would it be possible to just post the changed lines? They are usually easy to find by doing a "Search" for line(s) to be changed.
I feel your pain. Nevertheless, we should be grateful to Ken for all of the fantastic things he does for us. Sure, there were only four lines changed from V5.11 to V5.12, but with a file comparison program they were easy to spot. I use CompareIt! to identify and incorporate the changes into my significantly modified advforecast2.php so that my preferred large-icon presentation (https://www.gwwilkins.org/advforecast2.php) is preserved. I know where the changes I've made reside so I can safely bypass them during the file comparison.
-
Ah.. my bad. I've now updated to 5.12 with the corrected link to weather.gov pages for both point and zone forecasts.
*Sigh*
Sorry, but must be feeling lazy today after spending 4 hours yesterday finding the appropriate lines for adapting the stand-alone page script layout to my preferences....
I know I'm in the minority by using a stand-alone page (that has background and other layout modifications) but if there is only a line or two of change it would be a lot easier to change the altered line(s) than replace the whole page and then have to go back and change many lines of layout code.
If that is the case, only a line or two change, would it be possible to just post the changed lines? They are usually easy to find by doing a "Search" for line(s) to be changed.
You can make your life much easier (with a custom layout) by using the script to provide the data only and having your page do the printing of the HTML in the format you like.
Running <?php
$doPrintNWS = false;
include_once("advforecast2.php");
?>
will get the data (silently) on the page.
You can lift entire display code from the advforecast2.php script and rearrange to your hearts delight and just rely on the script for getting data -- would make future updates much easier.
If you're not using the Saratoga template set, you can even fake out all the Settings.php entries used before invoking the script, so you can just plop in an updated version with no customization required.
-
*Sigh*
Sorry, but must be feeling lazy today after spending 4 hours yesterday finding the appropriate lines for adapting the stand-alone page script layout to my preferences....
I know I'm in the minority by using a stand-alone page (that has background and other layout modifications) but if there is only a line or two of change it would be a lot easier to change the altered line(s) than replace the whole page and then have to go back and change many lines of layout code.
If that is the case, only a line or two change, would it be possible to just post the changed lines? They are usually easy to find by doing a "Search" for line(s) to be changed.
I'm in a similar situation. I happen to do my work on a Mac, which has Unix under the hood, and since I did a lot of development on Unix systems, I just resort to my old habits. But there is probably a more modern way to do this, no matter what the platform.
Anyway, here is what I do for files that I've modified:
1) Download the latest Ken update. I also save all of these, in separate folders indexed by the date I downloaded the update.
2) Using the Mac terminal (which gives me a Unix shell), I find the previous version of the same file in my Saratoga folder.
"find . -name '[file name]' -print | sort"
3) I then find the differences between those two versions. Example:
diff -w 20190430Update/advforecast2JSON.php 20190502Update/advforecast2JSON.php | more
(a. note that I rename the JSON versions of the advforecast files; b. "-w" means "ignore whitespace").
The output is:
58a59
> // Version 5.12 - 01-May-2019 - fix for link URL at bottom of page
61c62
< $Version = 'advforecast2.php (JSON) - V5.11 - 30-Apr-2019';
---
> $Version = 'advforecast2.php (JSON) - V5.12 - 01-May-2019';
388c389
< $backupfileName = APIURL . "/zones/JSON-LD/$NOAAZone/forecast";
---
> $backupfileName = APIURL . "/zones/forecast/$NOAAZone/forecast";
402c403
< $backupfileName = APIURL . "/zones/JSON-LD/".$META['forecastZone']."/forecast";
---
> $backupfileName = APIURL . "/zones/forecast/".$META['forecastZone']."/forecast";
1214c1215
< echo htmlspecialchars($zoneURL);
---
> echo htmlspecialchars(FCSTURL."/zone/".$META['forecastZone']);
1217c1218
< echo htmlspecialchars($pointURL);
---
> echo htmlspecialchars( FCSTURL."/point/".$META['point']);
4) In an editor, I open both my version of the file and Ken's latest. Following the results of the "diff", I apply the changes.
If we want to dig into this more and come up with procedures that are not so Unix (and Unix nerd) specific, we should probably start a new thread.
-
You can make your life much easier (with a custom layout) by using the script to provide the data only and having your page do the printing of the HTML in the format you like.
Running <?php
$doPrintNWS = false;
include_once("advforecast2.php");
?>
will get the data (silently) on the page.
You can lift entire display code from the advforecast2.php script and rearrange to your hearts delight and just rely on the script for getting data -- would make future updates much easier.
If you're not using the Saratoga template set, you can even fake out all the Settings.php entries used before invoking the script, so you can just plop in an updated version with no customization required.
Ah, yes, I do that too. Highly recommended.
-
Great! That's what was intended for easy standalone (non-template) usage. The hints on how what to provide in $SITE[] variables can be found in the script just below the settings info in the script. For advforecast2.php (JSON) that reads
// overrides from Settings.php if available
global $SITE;
if (isset($SITE['NWSforecasts'])) {$NWSforecasts = $SITE['NWSforecasts']; }
if (isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir']; }
if (isset($SITE['noaazone'])) {$NOAAZone = $SITE['noaazone'];}
if (isset($SITE['fcsturlNWS'])) {$fileName = $SITE['fcsturlNWS'];}
if (isset($SITE['fcsticonsdir'])) {$iconDir = $SITE['fcsticonsdir'];}
if (isset($SITE['fcsticonstype'])) {$iconType = $SITE['fcsticonstype'];}
if (isset($SITE['fcsticonsheight'])) {$iconHeight = $SITE['fcsticonsheight'];}
if (isset($SITE['fcsticonswidth'])) {$iconWidth = $SITE['fcsticonswidth'];}
if (isset($SITE['tz'])) {$ourTZ = $SITE['tz'];} // V5.00
if (isset($SITE['timeFormat'])) {$timeFormat = $SITE['timeFormat'];} // V5.00
if (isset($SITE['showTwoIconRows'])) {$showTwoIconRows = $SITE['showTwoIconRows'];} // V5.00
if (isset($SITE['showZoneWarning'])) {$showZoneWarning = $SITE['showZoneWarning'];} // V5.00
// end of overrides from Settings.php
so the including page can have <?php
$SITE = array();
global $SITE;
$doPrintNWS = false;
$SITE['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",
);
$SITE['cacheFileDir'] = './';
$SITE['noaazone'] = 'CAZ513';
$SITE['fcsturlNWS'] = 'http://forecast.weather.gov/MapClick.php?CityName=Saratoga&state=CA&site=MTR&textField1=37.2639&textField2=-122.022&e=1&TextType=2';
$SITE['fcsticonsdir'] = './forecast/images/';
$SITE['fcsticonstype'] = '.jpg';
$SITE['fcsticonsheight'] = 55;
$SITE['fcsticonswidth'] = 55;
$SITE['tz'] = 'America/Los_Angeles';
$SITE['timeFormat'] = 'g:i a T M d, Y';
$SITE['showTwoIconRows'] = true;
$SITE['showZoneWarning'] = true;
include_once("advforecast2.php");
?>
to make the script have all the required customizations applied without modifying the advforecast2.php script itself, and you can add whatever printing you want .. the data is what you get to use :)
To address the code versioning issue, I'll look at setting up a github distribution for all the standalone scripts now that I have some experience with it doing the Cumulus HomeWeatherStation template from Brian Underdown (https://github.com/ktrue/CU-HWS)
-
Not that I really needed more projects, but using GitHub is a good idea, so I've established repositories for all my Standalone-capable scripts at https://github.com/ktrue/
edit: I've decided to make separate repositories for each script set so it's easier to clone/track/download just that script.
I've added the advforecast2.php script there (at https://github.com/ktrue/NWS-forecast ) and will be populating the other parts of the distributions with the various current scripts over time. It's a bit labor-intensive (even with some automation help) to convert the existing HTML docs to MarkDown for the README.md in each directory for the scripts. I'm using Atom for the Markdown editor (and some repository add/commit) and GIT Bash for pushing.
For any scripts updated in the repository in the future, you'll be able to easily see the diff for the old->new versions provided by GIT automatically. Bonus...
-
Since we are a month out from being forced :grin:, I finally dropped the latest advforecast2.php 5.12 onto my site to replace the version 4.05 I was previously running. Works great! Thank you, Ken! [tup]
My only question relates to formatting on my alt-dashboard 6.95c (not a critical issue, just aesthetics). My site/dashboard is a little bit wider than the default (850px). The old forecast icons displayed perfectly aligned, the new forecast does not (old and new examples below). All of my usual formatting tricks are not working and it looks like the $forecasticons width may be handled differently in the new script? Does anyone have any ideas or suggestions for getting them to align evenly again?