Author Topic: NWS Alerts for multiple Zones - creating cron jobs  (Read 8253 times)

xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
NWS Alerts for multiple Zones - creating cron jobs
« on: May 01, 2015, 11:21:47 PM »
Anyone using a cron job to get multiple NWS alerts? If you have only one area (zone, city, county) you don't need these. OTOH, if you do and use some templates, you may get a warning at the very top of a page "suggesting" than you should use a cron job to save time.

I can eliminate that text/warning by eliminating all but one area/zone, but I'd like to have a total of three areas/zones, since I want to have alerts posted about nearby, but a fair distance away from my site. There are some instructions (in the template I'm using) that has a page that refers to using Windows Task Scheduler, which I don't exactly have installed, of course. I suspect the job can be created in Terminal, also. Alas, I don't have much more than a casual acquaintance with Terminal, but I'm more than willing to learn. It may be not much more than creating a file that is placed in the LaunchDaemons or LaunchAgents directories (either in System/Library/ or Library/). It may also be necessary to have this done at the we-hosting, server level.

I'm hoping that some here, being Mac oriented, will have some skills in doing this 'multi-area' alert job and be willing to share that with me. I could request help from the template dev, but this is probably an edge case and not something he usually needs to deal with. I also suspect he develops his template on Windows (or maybe Linux) and has enough problems with Mac users, anyway! :D

Thanks for any help you can offer! [computer]
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system


elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6494
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Try CronniX (Re: NWS Alerts for multiple Zones - creating cron jobs)
« Reply #1 on: May 01, 2015, 11:54:52 PM »
Dear xairbusdriver and WeatherCat Tinkerers,

Anyone using a cron job to get multiple NWS alerts? If you have only one area (zone, city, county) you don't need these. OTOH, if you do and use some templates, you may get a warning at the very top of a page "suggesting" than you should use a cron job to save time.

Sorry, but I'm afraid I'm missing some pieces of what you are trying to do.  Are you trying to do some sort of Web Scripting to grab some piece of information off of a National Weather Service web page?  Is there an example of what you are trying to do so we can get a better handle on the project you have in mind?

I can offer you one bit of advice.  There is a GUI front-end to cron for OS X called CronniX:

https://code.google.com/p/cronnix/

It works very nicely and is handy for things like launching AppleScripts or UNIX shell scripts.  It is open source so the price can't be beat!  [biggrin]

Cheers, Edouard  [cheers1]

xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #2 on: May 02, 2015, 01:20:45 AM »
UPDATED: This post refers to a site using a template. My current site is 90% hand-coded. The link below is valid but you won't see anything discussed in my comments there. [rolleyes2]

I could have shown you an example a few days ago when there was a Flood Alert for three different cities I want to include in on my site/region. They displayed just fine, that's not the problem. As a matter of fact, one can get NWS Alerts for every area they cover, if one were so inclined. ;D

The problem is that the template has scripts that notice that you are asking for more than one NWS area at a time and it then displays a bit of text suggesting that it could be less time consuming if one used a cron job. As I said, I can easily eliminate that text by limiting the Alerts to one area. That's not technically a problem, it is simply one that can be fixed by using a cron job (possibly on the web server) or with Windows Task Handled (which I suspect is nothing more than a windows version of an app like Terminal).

Part of the problem is that I live in an area that has three States within a 10 mile area. That means there could be NWS Alerts from ~100 miles west that would be good to know about, even though the local area is not covered.

OK, I'll simply remove a commented out line and show you the text. Give me a minute or two...

OK, visit the site and you'll see the text at the very top of the window. There are no current alerts, so there is nothing to actually display. All three of these areas are within the area I want to cover, however. Not all areas of the (western) Little Rock, AR or (southern) Jackson, MS areas are needed, but some of those are within 200 miles of my location. One cane even list the counties of interest.

I know where and what files display this text, but the simplest way to prevent it would be to create the cron job.

BTW, if you click the green "NONE" button, just below the "Active Alerts" button (lower, left-hand area, below the main nav buttons/list) you will get three NWS Alert areas I want to use.
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system


saratogaWX

  • Strong Breeze
  • ***
  • Posts: 156
  • Weather website programming enthusiast
    • Saratoga-Weather.org
  • Station Details: Davis VP1 +, iMAC 21, OSX 10.6.8
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #3 on: May 02, 2015, 03:08:48 AM »
The recommendation was for no more than 4 unique zones to be included in the nws-alerts script if a cron job were not used.

The reason is simple.. each check of the zone with the NWS takes a bit of time.. sometimes up to 2 seconds per zone.  If you have 4 zones in the list, that could add 8 seconds to the time the viewer sees your website (every 10 minutes or so).  That's quite a delay, so Curly and I settled on 4-max, then 'remind' if over 4 and no cron.

Yes, you can remove the warning if you like.. just keep in mind the possible extra delay in viewing your site for each zone added without using a cron.

The cron is intended to be run on the webserver hosting the website since that is where the data is to assemble your page resides.  It doesn't matter what client software your weather station is running (Mac, Win, Linux) if you are not running your site on the same machine.

If you are running the site on the same Mac as WeatherCat (not generally recommended), then using the GUI interface to local cron that Edouard suggested is a good idea.  I generally disrecommend folks running webservers on their home systems that open to the outside world as it is a security risk to your home system unless you've taken pains to harden/secure the local website.

I hope this helps...

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis Vantage Pro Plus - FARS, Boltek-PCI/NexStorm, GRLevel3, WD, WL, VWS, Cumulus, Meteohub, WeatherSnoop, WeatherCat
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #4 on: May 02, 2015, 03:32:12 AM »
Quote
The cron is intended to be run on the webserver hosting the website since that is where the data is to assemble your page resides.
That's what I thought. Downloaded CronniX, anyway; I figured Edoudard might be getting a kickback on each download... [lol]
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system


wvdkuil

  • Strong Breeze
  • ***
  • Posts: 151
    • DW8113 (D8113)
    • IVLAAMSG47
    • Weatherstation Wilsele/Leuven/Belgium
  • Station Details: VantagePro2+ UV,Solar - Macbook/Mini
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #5 on: May 02, 2015, 10:04:01 AM »
There are multiple ways to run a cronjob in this case.
1: we define what should be run. Using the Leuven-Template the "job" to be executed is
Code: [Select]
http://www.your weather site.com/weather2/index2.php?mu=1A "special version" of the main startpage  should be run
=> just to discard all output and display a succes message and some time info
and use the command mu=1
=> tells the Curly / NWS scripts to load the latest warnings

2:  we set the nocron to false  in line 41 of the nws-alerts-config.php
From now on NO more updates every time a visitor comes to the website.  There will only be updates if we use mu=1 on a start page.

3: We test by typing in the browser the normal website address with an extra mu=1:
Code: [Select]
http://www.your weather site.com/weather2/index.php?mu=1There should be no errors.

4: We search for an inexpensive / free cron facility.
4.1  Use taskmanager on Windows or cronnix on a Mac.  As the PC/Mac is running 24/24 that is a "no extra" costs choice.
4.2 To add more 24/7 availability one can use an external cronjob server
4.2.1  your own hoster, although most do not allow frequent (every 10 minutes) jobs
4.2.2 Companies like
cronjob-de https://www.cronjob.de/preise.php free 1 job minimum 5 minutes between jobs or
setcronjob-com https://www.setcronjob.com/prices free minimum 30 minutes, 10$/year  minimum 2 minutes

Using such a company gives you often a log so you can check the history and for example see when the response times were not OK.
Code: [Select]
Datum: 02.05.2015, 10:56 Uhr
Ausgabe:   succes, time spent in seconds: 0.30454802513123

Datum: 02.05.2015, 10:51 Uhr
Ausgabe:  succes, time spent in seconds: 0.42925810813904

Datum: 02.05.2015, 10:46 Uhr
Ausgabe: succes, time spent in seconds: 2.7354168891907   

off-topic
Another advantage of not using a subset of the main page but executing the complete  index2/index.php:  All other out of cache time files (forecast, Metar for current conditions, nightly almanac data, a.s.o. ) are loaded also. The next human visitor gets a better response this way. 

Wim
Support of Leuven-Template&Scripts: https://support.leuven-template.eu/
Support and demo for the PWS_Dashboard (also for WeatherCat)  https://pwsdashboard.com/ 
My PWS at home https://weer.sluispark.be/
And at my daughters house https://www.weerstation-herent.be/

xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #6 on: May 02, 2015, 03:26:30 PM »
Thanks Wim, lots of tactics to pursue. [tup] Good thing I don't have a day job! [lol] ;D
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system


xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #7 on: May 02, 2015, 04:04:17 PM »
Tried Wim's steps 1, 2, 3 above:
  • First, I assumed the 'extra' "2" in the url wuz an erer (http://...weather2/index2.php?mu=1) or, more likely, just copied from his own set up.
  • Changed $noCron value to false. Somewhat confusing logic since I am still not using cron. I accepted with blind faith, that Wim knows what he's talking about. That's certainly been the case in all my conversations with him! [tup]
  • Refreshed the page after uploading the edited nws-alerts-config.php
  • cron warning text gone! [cheer]
  • Added the "?mu=1" to the url and still no errors.
Not sure what will happen if/when an actual NWS Alert is active for one or more of the areas, however. I'm sure the weather will soon enough provide a real world test.

Frankly, I'm a little confused by these comments:
Quote
A "special version" of the main startpage  should be run
=> just to discard all output and display a succes message and some time info and use the command mu=1
=> tells the Curly / NWS scripts to load the latest warnings
Obviously, a "special version" displayed, since there was no 'cron text', but I assumed that simply changing the $noCron to false took care of that.
However, I'm not seeing any "success message and some time info", at least not in any obvious place. Using the 'hidden' Summary link does show the three areas and the last update time/date. Is that the "success message" being referred to?
Lastly, since there is actually no cron job, I'm assuming (I'm doing an awful lot of that!) that any updates to these Alerts will be done only when the page is opened or with a manual page refresh command. After re-reading the instructions, I think I understand this a bit better. The NWS Alerts will only be seen if the "?mu=1" is in the url. Making a bookmark with that in the url is an easy fix. Getting users to do that manually, even once and making a bookmark out of it is an 'animal of a different color'. Obviously, this solution is not acceptable since 'regular viewers' will only see the small banner showing "No Alerts" if they don't know to add the mu=1.

I'll look into the cronjob server options soon. First I'll check with my hosting company.

Thanks so much for all the great, useful, and rapid info and support!
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system


wvdkuil

  • Strong Breeze
  • ***
  • Posts: 151
    • DW8113 (D8113)
    • IVLAAMSG47
    • Weatherstation Wilsele/Leuven/Belgium
  • Station Details: VantagePro2+ UV,Solar - Macbook/Mini
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #8 on: May 02, 2015, 04:11:33 PM »
Tried Wim's steps 1, 2, 3 above:
  • First, I assumed the 'extra' "2" in the url wuz an erer (http://...weather2/index2.php?mu=1) or, more likely, just copied from his own set up.
  • Changed $noCron value to false. Somewhat confusing logic since I am still not using cron. I accepted with blind faith, that Wim knows what he's talking about. That's certainly been the case in all my conversations with him! [tup]
  • Refreshed the page after uploading the edited nws-alerts-config.php
  • cron warning text gone! [cheer]
  • Added the "?mu=1" to the url and still no errors.
Not sure what will happen if/when an actual NWS Alert is active for one or more of the areas, however. I'm sure the weather will soon enough provide a real world test.

Frankly, I'm a little confused by these comments:
Quote
A "special version" of the main startpage  should be run
=> just to discard all output and display a succes message and some time info and use the command mu=1
=> tells the Curly / NWS scripts to load the latest warnings
Obviously, a "special version" displayed, since there was no 'cron text', but I assumed that simply changing the $noCron to false took care of that.
However, I'm not seeing any "success message and some time info", at least not in any obvious place. Using the 'hidden' Summary link does show the three areas and the last update time/date. Is that the "success message" being referred to?
Lastly, since there is actually no cron job, I'm assuming (I'm doing an awful lot of that!) that any updates to these Alerts will be done only when the page is opened or with a manual page refresh command. I can live with these assumptions, even if the details are wrong. The page works fine, at least with few/no NWS Alerts (and it worked fine even with three duplicate Flood Alerts).

I'll look into the cronjob server options later. First I'll check with my hosting company.

Thanks so much for all the great, useful, and rapid info and support!
The special version of index.php is attached to my previous post and indeed it is called index2.php
That version does not output the whole html page, only a message.

All further settings are correct.

So you should
1. unzip index2.php and put it in the weather2 folder.

2. test this link http://mailscamalert.com/weather2/index2.php?mu=1

3. run  this link http://mailscamalert.com/weather2/index2.php?mu=1
every 10 minutes
using using whatever scheduler (this one is VERY simple app for your Mac:  http://macscheduler.net/)

The mu=1 makes sure that the nws scripts check if there are warnings. you will see them on your normal (index.php) pages.
 
Support of Leuven-Template&Scripts: https://support.leuven-template.eu/
Support and demo for the PWS_Dashboard (also for WeatherCat)  https://pwsdashboard.com/ 
My PWS at home https://weer.sluispark.be/
And at my daughters house https://www.weerstation-herent.be/

wvdkuil

  • Strong Breeze
  • ***
  • Posts: 151
    • DW8113 (D8113)
    • IVLAAMSG47
    • Weatherstation Wilsele/Leuven/Belgium
  • Station Details: VantagePro2+ UV,Solar - Macbook/Mini
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #9 on: May 02, 2015, 04:28:50 PM »
I understand your worries if the nws alerts are realy refreshed. And indeed the name index2.php is not very clear for what it is.
So attached a script with the self-explaining name cron_job.php

Unzip, place in weather2/ folder

The url to execute as cron becomes http://mailscamalert.com/weather2/cron_job.php?mu=1
This will not only output a message for succes, but also the date/time of the nws files.

succes, time spent in seconds: 0.96099996566772
changed from May 2 2015 11:25 am toMay 2 2015 11:26 am


Wim
Support of Leuven-Template&Scripts: https://support.leuven-template.eu/
Support and demo for the PWS_Dashboard (also for WeatherCat)  https://pwsdashboard.com/ 
My PWS at home https://weer.sluispark.be/
And at my daughters house https://www.weerstation-herent.be/

xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #10 on: May 02, 2015, 04:43:55 PM »
I was posting as you were! I stand corrected about the file name and I now see there was an actual download link.
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system


xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #11 on: May 02, 2015, 09:30:02 PM »
Almost there! At least for checking or updating NWS Alerts. I added the two extra files you created (index2.php and cron_job.php) and they do provide some info. I did make minor spelling corrections and added a bit of text to verify which file was out putting the text.

Running the http://www.mailscamalert/weather2/index2.php?mu=1 gives me this and nothing else on a blank page:
Success, time spent in seconds: 0.744896888733
That seems correct.

Running http://www.mailscamalert/weather2/cron_job.php?mu=1 shows the following and nothing else on a blank page:
Success (from running cron_job.php), time spent in seconds: 0.929280996323
Notice: Undefined variable: save_nws_filename in /home3/xairbus2/public_html/weather2/cron_job.php on line 29

Notice: Undefined variable: save_nws_filemtime in /home3/xairbus2/public_html/weather2/cron_job.php on line 30

Notice: Undefined variable: save_nws_updateTime in /home3/xairbus2/public_html/weather2/cron_job.php on line 35

Notice: Undefined variable: save_nws_filename in /home3/xairbus2/public_html/weather2/cron_job.php on line 37 [banghead]
No change in settings (updatetime = ) filetime : Dec 31 1969 6:00 pm


I could add a  bit of code to eliminate the "Undefined variables" notices by uncommenting the code.
line 19 #$save_nws_filename = $save_nws_filemtime = $save_nws_updateTime = "";
However, it will still output the same ?bogus? date (Dec 31 1969 6:00 pm) and the $save_nws_updateTime value is still set to nothing.

I'm sure I'm doing something simply stupid. Or else the NWS sets the date for all expired Alerts to Dec 31 1969 6:00 pm.
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system


wvdkuil

  • Strong Breeze
  • ***
  • Posts: 151
    • DW8113 (D8113)
    • IVLAAMSG47
    • Weatherstation Wilsele/Leuven/Belgium
  • Station Details: VantagePro2+ UV,Solar - Macbook/Mini
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #12 on: May 02, 2015, 09:52:57 PM »
Almost there! At least for checking or updating NWS Alerts. I added the two extra files you created (index2.php and cron_job.php) and they do provide some info. I did make minor spelling corrections and added a bit of text to verify which file was out putting the text.

Running the http://www.mailscamalert/weather2/index2.php?mu=1 gives me this and nothing else on a blank page:
Success, time spent in seconds: 0.744896888733
That seems correct.

Running http://www.mailscamalert/weather2/cron_job.php?mu=1 shows the following and nothing else on a blank page:
Success (from running cron_job.php), time spent in seconds: 0.929280996323
. . .  shortened . . .
So the index2.php should be used then for now if you already found a solution for you cron.
I tried to get the data-times of the new nws files, but that was no succes then
.
I will tomorrorw in my daytime check why  that script does not work.

===
The blank page is on purpose. 
Most cron servers only allow a small message not a whole page. So all normal output is removed, only the essential information is returned, as in index2.php

===


But all of this is not that  important. 

But this is: For the moment, if you DID NOT find a cron-server, please change back the $nocron setting so that the warnings are retrieved as long as you have no cron server/program.

Wim
Support of Leuven-Template&Scripts: https://support.leuven-template.eu/
Support and demo for the PWS_Dashboard (also for WeatherCat)  https://pwsdashboard.com/ 
My PWS at home https://weer.sluispark.be/
And at my daughters house https://www.weerstation-herent.be/

xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #13 on: May 02, 2015, 10:34:00 PM »
Will do. No need for you to do any work on this, please take the rest of the weekend off! [tup]

Since the template allowed up to four areas/counties before posting the "cron" warning, I simply removed the county portion of the NWS areas, leaving just the Zones. That reduced the searches to just three rather than the six previously used.

Results:
Possibly quite distance Alerts.
No more extra text at the top of the page.

Pay the Clerk. Case closed. Next?! ::)
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system


xairbusdriver

  • Storm
  • *****
  • Posts: 3126
    • EW7115 (E7115)
    • KTNGERMA20
    • Mid-South Weather
  • Station Details: Davis VP2 wireless + remote Anemometer/2014 Mac min - 10.15.7/WC 3.0.5
Re: NWS Alerts for multiple Zones - creating cron jobs
« Reply #14 on: May 03, 2015, 01:36:29 AM »
Ken and curly,

I've been answering/asking so many people the last few days I'm not sure what I said nor when. You mentioned in a post that you and "curly" had the 'cron' warning/suggestion come up if the site was requesting more than four different places. I may have written that my experience was different. Some may think that this was a problem in your code! That is definitely not the case!

Once more, my poor scanning and lack of usable brain cells caused me to make erroneous statements. I caused the warning not because I had more than four "areas" requested, but because I had two "areas" in each of three cities enumerated. [banghead] I first selected the three cities within the general region I am interested in. I then foolishly started selecting well over a dozen counties around that are physically nearby. What I have still not investigated is exactly what counties are included in the NWS Alert for the 30+ cities they use. Not knowing this, I ended up with some 50+ individual requests! Only slightly over what you and "curly" suggested as a limit! [goofy]

My first "solution" was to pared down that list to the three cities with one zone and one county in each. However, that is actually still six requests, not three. So my "solution" was still causing the 'cron warning' text. Obviously, I need to study a bit more about how to select NWS Alert areas!

Sorry for my confusion and especially implying that the Saratoga scripts were part of the problem. [blush]
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system