WXforum.net
Web Weather => Weather Website PHP/AJAX scripting => Topic started by: tmabell on January 22, 2018, 08:37:39 AM
-
We are going to need to update NWS-Alerts.php for three new product types. They are in use now or will be soon.
The new products are described here:
https://nws.weather.gov/products/docs/PDD-NewSnowSqualWarning.pdf
and here:
https://nws.weather.gov/products/docs/PDD-DustStormWarningandAdvisoryProducts.pdf
-
They're changing the lake snow warnings again? They made some odd changes for this season already.
-
It's possible that nws-alerts.php will need some additions for new codes.
Unfortunately, some of the detail links now result in a redirect to http://governmentshutdown.noaa.gov/ so I'll have to wait a bit for the docs to come back online.
The two new ones appear to be SVS (SQW?) for Snow Squall Warning and DSY for Dust Storm Warning. The SVS code (Severe Weather Warning) already is handled by nws-alerts.php, but the DSY one is missing.
But.. when the government is back 'online', I'll check it out further. Thanks for the heads-up.
-
I hoisted the documents on my site
https://mymishawakaweather.com/docs/PDD-DustStormWarningandAdvisoryProducts.pdf
https://mymishawakaweather.com/docs/PDD-NewSnowSqualWarning%20.pdf
-
The PDFs work fine from the links.. apparently, requests to .htm/.html files result in the redirect to the shutdown page. Same is true on the alerts.weather.gov for non-PDF documentation. :(
-
The release date for the 'SCN17-112: Updated: Polygon-based Snow Squall Warnings to begin on or about January 31, 2018, for select offices and Polygon-based Dust Storm Warnings and Dust Advisory Product Operational Demonstration at select WFOs on or about June 20, 2018', as shown, has now been pushed back considerably, so no rush.
-
The snow squall product is delayed for some offices yes but already in use at others. The dust storm product is still months away.
-
I'd love to get a XML capture of a Snow Squall (and a Dust Storm) alert so I could see what needs to be added (code, images) to the script. Please post an XML sample if you happen to see one.
-
Some Lake Effect Snow is expected tonight off Lake Ontario. I'll see if NWS Buffalo issues anything (if I remember to check)
-
How would we locate the xml in order to capture it?
Dennis
-
I'd recommend using view-source:https://alerts.weather.gov/cap/ny.php?x=1 (and replace 'ny' with your state's 2 character abbreviation.
Then copy/paste the page into a [code] ... [/code] entry in a post. That will capture all I need to see about the new alert.
-
Thanks Ken, will keep my eye out for the use of the new alerts.
Dennis
-
Just a small note.. you only have to capture the <entry>...</entry> section for the particular alert with the Squall warning. Like
<entry>
<id>https://alerts.weather.gov/cap/wwacapget.php?x=NY125A8D218C08.FloodWarning.125A8D2ED020NY.ALYFLWALY.a0e07da60260394ce677be75f4deeab4</id>
<updated>2018-01-24T09:26:00-05:00</updated>
<published>2018-01-24T09:26:00-05:00</published>
<author>
<name>w-nws.webmaster@noaa.gov</name>
</author>
<title>Flood Warning issued January 24 at 9:26AM EST until January 24 at 8:20PM EST by NWS</title>
<link href="https://alerts.weather.gov/cap/wwacapget.php?x=NY125A8D218C08.FloodWarning.125A8D2ED020NY.ALYFLWALY.a0e07da60260394ce677be75f4deeab4"/>
<summary>The National Weather Service in Albany has issued a * Flood Warning for... Central Warren County in east central New York... * Until 930 AM EST Thursday * At 924 AM EST, emergency management continues to report flooding along Route 418 between Thurman and Warrensburg, and along River</summary>
<cap:event>Flood Warning</cap:event>
<cap:effective>2018-01-24T07:01:00-05:00</cap:effective>
<cap:expires>2018-01-24T20:20:00-05:00</cap:expires>
<cap:status>Actual</cap:status>
<cap:msgType>Alert</cap:msgType>
<cap:category>Met</cap:category>
<cap:urgency>Expected</cap:urgency>
<cap:severity>Moderate</cap:severity>
<cap:certainty>Likely</cap:certainty>
<cap:areaDesc>Warren</cap:areaDesc>
<cap:polygon>43.61,-73.79 43.48,-73.75 43.46,-73.84 43.6,-73.9 43.61,-73.79</cap:polygon>
<cap:geocode>
<valueName>FIPS6</valueName>
<value>036113</value>
<valueName>UGC</valueName>
<value>NYC113</value>
</cap:geocode>
<cap:parameter>
<valueName>VTEC</valueName>
<value>/O.NEW.KALY.FA.W.0009.180124T1426Z-180125T1430Z/
/00000.0.IC.000000T0000Z.000000T0000Z.000000T0000Z.OO/</value>
</cap:parameter>
</entry>
-
I have taken Curly's last release (V1.41) and updated it to V1.42 with all the PHP7+ fixes needed.
It does not include the Snow Squall or Dust Storm warning additions as I've not received any captures of the XML for either.
Now available for Saratoga templates at update tool page (https://saratoga-weather.org/wxtemplates/updates.php) with query 27-Jan-2018, Base-USA, Plugin-*
Also, the standalone package is now on the legacy scripts (https://saratoga-weather.org/scripts-legacy.php#curly) page.
Best regards,
Ken
-
Did the update, thanks
I like the new feature showing no watches warnings etc.
[ You are not allowed to view attachments ]
-
Thanks a million Ken!
-
Hey Ken,
Is nws-alerts-summary-inc.php 1.02 missing its "meat"? If I diff with previous version, all I get is the added version comment.
10a11
> // Version 1.02 - 27-Jan-2018 - updates for PHP7+ and nws-alerts V1.42
I know there were a few array definitions that I had to pop into my local version (e.g., $aav, $atomAlerts).
-
The nws-alerts-summary-inc.php didn't require updates from his V1.41 version, but I revved it since it was a bit different from the V1.37 version included in the templates (so it would be included in the template update).
My main concern was to have all the needed update file appear in the template update set so minor mods(usually versioning) were made to have that happen.
The bulk of the changes needed for PHP 7.x changes had to do with initializing variables as strings then using them as arrays. Changing the initialization to a blank array cured those errors. The main changes in nws-alerts.php beyond that had to do with globalizing the $noted variable, replacing a $name() function calls for fetching data to a static call (so that code wouldn't trip malware scanners, as calling a variable named function is a frequently used malware trick) and using curl only (with some logic to ensure all the needed curl functions were present).
For a complete update of template websites, both a version and a filemtime() on the file is needed so some (like the new .png file) were just 'touched' to accomplish that.
Hope this helps...
-
OK, thanks. Another nit - nws-alerts.php is missing it's closing " ?> ". 8-)
-
The missing ?> at the end is a 'feature', not a 'bug'.
The PHP community has debated about including it or not and decided that for PHP, it's recommended to leave it off the end when there is no HTML/non PHP following the script to prevent early headers from being caused by trailing newlines after the closing ?>
https://stackoverflow.com/questions/3219383/why-do-some-scripts-omit-the-closing-php-tag
http://php.net/manual/en/language.basic-syntax.phptags.php
-
did you still need the snow squall warning info Ken? Had a warning this morning.
<?xml version = '1.0' encoding = 'UTF-8' standalone = 'yes'?>
<?xml-stylesheet href='capatomproduct.xsl' type='text/xsl'?>
<!--
This atom/xml feed is an index to active advisories, watches and warnings
issued by the National Weather Service. This index file is not the complete
Common Alerting Protocol (CAP) alert message. To obtain the complete CAP
alert, please follow the links for each entry in this index. Also note the
CAP message uses a style sheet to convey the information in a human readable
format. Please view the source of the CAP message to see the complete data
set. Not all information in the CAP message is contained in this index of
active alerts.
-->
<alert xmlns = 'urn:oasis:names:tc:emergency:cap:1.1'>
<!-- http-date = Fri, 02 Feb 2018 02:28:24 GMT -->
<identifier>NOAA-NWS-ALERTS-NY125A91C7BC68.SnowSquallWarning.125A91C7DE4CNY.BGMSQWBGM.644df37eb4b1ef5f1f4e91128489a7ee</identifier>
<sender>w-nws.webmaster@noaa.gov</sender>
<sent>2018-02-02T09:28:24-05:00</sent>
<status>Actual</status>
<msgType>Alert</msgType>
<scope>Public</scope>
<note>Alert for Cayuga; Chenango; Cortland; Madison; Onondaga; Otsego; Tompkins (New York) Issued by the National Weather Service</note>
<info>
<category>Met</category>
<event>Snow Squall Warning</event>
<urgency>Expected</urgency>
<severity>Extreme</severity>
<certainty>Likely</certainty>
<eventCode>
<valueName>SAME</valueName>
<value>SQW</value>
</eventCode>
<effective>2018-02-02T09:27:00-05:00</effective>
<expires>2018-02-02T10:15:00-05:00</expires>
<senderName>NWS Binghamton (South Central New York and Northeastern Pennsylvania)</senderName>
<headline>Snow Squall Warning issued February 02 at 9:28AM EST until February 02 at 10:15AM EST by NWS Binghamton</headline>
<description>...Snow Squall Warning issued February 2 at 9:27AM EST expiring
February 2 at 10:15AM EST by NWS Binghamton NY...
The National Weather Service in Binghamton has issued a
* Snow Squall Warning for...
Northern Otsego County in central New York...
Madison County in central New York...
Southern Cayuga County in central New York...
Northern Cortland County in central New York...
Southern Onondaga County in central New York...
Northeastern Tompkins County in central New York...
Northern Chenango County in central New York...
* Until 1015 AM EST.
* At 927 AM EST, a dangerous snow squall was located along a line
extending from Unadilla Forks to near Morrisville to near
Cazenovia to near Otisco to Casowasco to near Aurora, moving
southeast at 25 mph.
HAZARD...Extremely poor visibility in heavy snow.
SOURCE...Radar indicated.
IMPACT...Dangerous life-threatening travel.
This snow squall will be near...
Cazenovia around 935 AM EST.
Madison and Solsville around 940 AM EST.
Tully around 945 AM EST.
Nelson and Exeter Center around 950 AM EST.
Genoa and Erieville around 955 AM EST.
Scott and Fabius around 1000 AM EST.
Morrisville around 1005 AM EST.
Cooperstown, Brookfield and Locke around 1010 AM EST.
This includes New York Interstate 81 between exits 11 and 15.
PRECAUTIONARY/PREPAREDNESS ACTIONS...
Reduce your speed and turn on headlights! During snow squalls, the
visibility may suddenly drop to near zero in whiteout conditions.</description>
<instruction></instruction>
<parameter>
<valueName>WMOHEADER</valueName>
<value></value>
</parameter>
<parameter>
<valueName>UGC</valueName>
<value>NYC011-017-023-053-067-077-109</value>
</parameter>
<parameter>
<valueName>VTEC</valueName>
<value>/O.NEW.KBGM.SQ.W.0001.180202T1427Z-180202T1515Z/</value>
</parameter>
<parameter>
<valueName>TIME...MOT...LOC</valueName>
<value></value>
</parameter>
<area>
<areaDesc>Cayuga; Chenango; Cortland; Madison; Onondaga; Otsego; Tompkins</areaDesc>
<polygon>42.67,-74.64 42.69,-75.62 42.64,-75.97 42.52,-76.43 42.62,-76.66 42.67,-76.68 42.71,-76.73 42.75,-76.74 42.81,-76.53 42.93,-76.27 42.98,-75.97 42.95,-75.67 42.9,-75.44 42.86,-75.43 42.87,-75.31 42.67,-74.64 42.67,-74.64</polygon>
<geocode>
<valueName>FIPS6</valueName>
<value>036011</value>
</geocode>
<geocode>
<valueName>FIPS6</valueName>
<value>036017</value>
</geocode>
<geocode>
<valueName>FIPS6</valueName>
<value>036023</value>
</geocode>
<geocode>
<valueName>FIPS6</valueName>
<value>036053</value>
</geocode>
<geocode>
<valueName>FIPS6</valueName>
<value>036067</value>
</geocode>
<geocode>
<valueName>FIPS6</valueName>
<value>036077</value>
</geocode>
<geocode>
<valueName>FIPS6</valueName>
<value>036109</value>
</geocode>
<geocode>
<valueName>UGC</valueName>
<value>NYC011</value>
</geocode>
<geocode>
<valueName>UGC</valueName>
<value>NYC017</value>
</geocode>
<geocode>
<valueName>UGC</valueName>
<value>NYC023</value>
</geocode>
<geocode>
<valueName>UGC</valueName>
<value>NYC053</value>
</geocode>
<geocode>
<valueName>UGC</valueName>
<value>NYC067</value>
</geocode>
<geocode>
<valueName>UGC</valueName>
<value>NYC077</value>
</geocode>
<geocode>
<valueName>UGC</valueName>
<value>NYC109</value>
</geocode>
</area>
</info>
</alert>
-
I can also confirm a snow squall warning correctly displayed on my page however i am not sure how it did since there is no "snow squall warning" code built into any of my alert files ???
-
The nws-alerts.php has a generic process in the get_icon() function that uses partial matches (like to 'Watch', 'Warning', etc) that returns a generic icon and severity based on that partial match to the event title. So the 'Warning' in 'Snow Squall Warning' was handled as a generic warning-level alert and the generic warning icon was used.
// if alert type is not in list
if (strpos($evnt,"Warning") !== false) {
$a['color'] = "#D11";
$a['severity'] = 46;
$a['icon'] = 'SVW.gif';
return $a;
}
if (strpos($evnt,"Advisory") !== false) {
$a['color'] = "#F60";
$a['severity'] = 83;
$a['icon'] = 'SWA.gif';
return $a;
}
if (strpos($evnt,"Watch") !== false) {
$a['color'] = "#F30";
$a['severity'] = 119;
$a['icon'] = 'SWA.gif';
return $a;
}
if (strpos($evnt,"Statement") !== false) {
$a['color'] = "#C70";
$a['severity'] = 139;
$a['icon'] = 'SWA.gif';
return $a;
}
I'm glad Curly did that.. helps protect against failures for new specific watch/warning/advisory titles.
I'll issue an update with both Dust Storm Warning/watch/advisory and Snow Squall Warning/watch/advisory to have the correct icons used instead. Thanks for capturing the XML :)
-
I keep getting "nws-alerts: Checking more than four warning/county codes can delay the loading of your pages. You should use a cron job to get the data." regardless of my settings in nws-alerts-config.php. Also, I think that I only have three county codes, not more than four.
In the nws-alerts-config.php file I have:
## GENERAL SETTINGS
$noCron = false; // true=not using cron, update data when cache file expires false=use cron to update data
$updateTime = 600; // IF $noCron=true - time span in seconds to retain cache file before updating
$floodType = true; // true=add prefix 'Areal' or 'River' to Flood alert title false=no prefix to Flood alert
$noAlertText = 'No Warnings, Watches, or Advisories'; // Text to display for no alerts.
Here are the $myZC array settings:
$myZC = array(
"Presque Isle County|MIZ018|MIC141",
"Alpena|MIZ024|MIC007",
"Cheboygan|MIZ017|MIC031"
// "Santa Cruz Mtns|CAZ512|CAC081|CAC085|CAC087",
// "Santa Cruz|CAZ529|CAC087",
// "Monterey|CAZ530|CAC053",
// "South/East Bay|CAZ508|CAC081",
// "San Mateo Coast|CAZ509|CAC081",
// "San Francisco|CAZ006|CAC075"
);
I tried $noCron=true and the update time to just 6 seconds to see if that would work.
I set up a cron job in my control panel for:
/home/rogersci/public/nws-alerts.php
I still get the four county warning no matter what I do. I also purged the Cloudflare cache.
Any ideas?
Greg H.
-
Hi Greg,
I count 6 unique zones in your list .. each unique ssZnnn and ssCnnn entry counts in the zone count.
You should set $noCron = true; if you DO NOT have a cron job. Set $noCron = false; if you DO have a cron job (kinda counterintuitive, but thats the way it works).
With $noCron = true; the script will check the cache files for 'freshness' and automatically reload as needed when invoked in menubar.php (in the Saratoga template set).
If $noCron = false, then the menubar.php invocation of the script will NOT cause new data to be fetched. Only a direct call (via a cron job) to load nws-alerts.php will cause cache 'freshness' and reload of data.
So.. you have 6 zones, and you'll get the 'More than 4' message unless you either prune back your zone count to 4 or set up a cron job (and set $noCron = false; ) to run nws-alerts.php
For a cron job, you generally have to do more than just adding a PHP script name as a command. A small bash script like #!/bin/bash
# cron job to run nws-alerts.php
#
# --- begin settings
HDIR="$HOME/httpdocs/wx/AWN"
SCRIPT=nws-alerts.php
URL="http://saratoga-weather.org/$SCRIPT"
PHPcmd=/usr/bin/php
CURLcmd=/usr/bin/curl
USECMD=PHP
#USECMD=CURL
# --- end settings
cd $HDIR
# Use one or the other .. direct is prefered over curl
if [ "$USECMD" == "PHP" ]
then
$PHPcmd -q $SCRIPT 2>&1 /dev/null
fi
if [ "$USECMD" == "CURL" ]
then
$CURLcmd -s $URL 2>&1 /dev/null
fi
#
Note: that bash script has to be edited to use only \n (new-line) characters as line endings. Windows \r\n (carriage-return, new-line) will cause bash to barf on the script (so it won't run). Use notepad++ and show-line-endings to make sure only NL characters are there.
Then a cron entry like */10 * * * * bash "$HOME/httpdocs/my-cron.txt"
will work to invoke the script. Be sure to change the HDIR, URL, PHPcmd, CURLcmd entries to match where your home directory, php-cli processor and curl are located. cron and bash are unforgiving about mis-specified file locations.
-
Thanks Ken.
Here is my script get-nwsalerts-script.sh
#!/usr/local/bin/bash
# cron job to run nws-alerts.php
#
# --- begin settings
HDIR="/home/rogersci/public_html"
SCRIPT=nws-alerts.php
URL="http://rogerscityweather.com/$SCRIPT"
PHPcmd=/usr/local/bin/php
CURLcmd=/usr/local/bin/curl
USECMD=PHP
#USECMD=CURL
# --- end settings
cd $HDIR
# Use one or the other .. direct is prefered over curl
if [ "$USECMD" == "PHP" ]
The cron in the control panel invokes it every 5 minutes.
The strange thing was the warning didn't clear until I commented out one of the counties. Strangely enough, when I un-commented it to restore the county, it all started working correctly without the message. Maybe it was cached.
Thanks for your help, Ken.
Greg H.
-
Ken, I remembered this thread but only after I had sent the email about the SQW. My apologies! For now, I made the addition to my version manually but I still look forward to your next update. Thanks for all that you do and Happy Holidays!