{"id":7050,"date":"2019-09-15T20:36:54","date_gmt":"2019-09-16T00:36:54","guid":{"rendered":"https:\/\/alt-fw.org\/public\/?p=7050"},"modified":"2020-09-15T22:50:31","modified_gmt":"2020-09-16T02:50:31","slug":"server-side-weather-data-collection-script-for-gnu-linux","status":"publish","type":"post","link":"https:\/\/alt-fw.org\/public\/?p=7050","title":{"rendered":"Server Side Weather data collection script for GNU\/Linux"},"content":{"rendered":"<figure id=\"attachment_7051\" aria-describedby=\"caption-attachment-7051\" style=\"width: 300px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/w1.weather.gov\/xml\/current_obs\/\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"7051\" data-permalink=\"https:\/\/alt-fw.org\/public\/?attachment_id=7051\" data-orig-file=\"https:\/\/i0.wp.com\/alt-fw.org\/public\/wp-content\/uploads\/2020\/09\/weather-caps-picture.png?fit=544%2C218&amp;ssl=1\" data-orig-size=\"544,218\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"XML Feeds of Current Weather Conditions\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;see https:\/\/w1.weather.gov\/xml\/current_obs\/ and https:\/\/alerts.weather.gov\/&lt;\/p&gt;\n\" data-large-file=\"https:\/\/i0.wp.com\/alt-fw.org\/public\/wp-content\/uploads\/2020\/09\/weather-caps-picture.png?fit=544%2C218&amp;ssl=1\" class=\"size-medium wp-image-7051\" src=\"https:\/\/i0.wp.com\/alt-fw.org\/public\/wp-content\/uploads\/2020\/09\/weather-caps-picture.png?resize=300%2C120&#038;ssl=1\" alt=\"\" width=\"300\" height=\"120\" srcset=\"https:\/\/i0.wp.com\/alt-fw.org\/public\/wp-content\/uploads\/2020\/09\/weather-caps-picture.png?resize=300%2C120&amp;ssl=1 300w, https:\/\/i0.wp.com\/alt-fw.org\/public\/wp-content\/uploads\/2020\/09\/weather-caps-picture.png?resize=150%2C60&amp;ssl=1 150w, https:\/\/i0.wp.com\/alt-fw.org\/public\/wp-content\/uploads\/2020\/09\/weather-caps-picture.png?w=544&amp;ssl=1 544w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-7051\" class=\"wp-caption-text\">see <a href=\"https:\/\/w1.weather.gov\/xml\/current_obs\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/w1.weather.gov\/xml\/current_obs\/<\/a> and <a href=\"https:\/\/alerts.weather.gov\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/alerts.weather.gov\/<\/a><\/figcaption><\/figure>\n<p>The following script is intended to run on your file server that collects data to distribute to your network. Safety is built in to prevent contacting NOAA weather.gov more than one time per hour. The data comes in .xml format and contains the recommended time to collect the data, per each region. Information on what files to request can be found by much digging and a visit to <strong>XML Feeds of Current Weather Conditions<\/strong> <a href=\"https:\/\/w1.weather.gov\/xml\/current_obs\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/w1.weather.gov\/xml\/current_obs\/<\/a> and <strong>NWS Public Alerts in XML\/CAP and ATOM Formats<\/strong> <a href=\"https:\/\/alerts.weather.gov\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/alerts.weather.gov\/<\/a> combined with close attention to the browser URL when you look at your weather on <a href=\"http:\/\/weather.gov\" target=\"_blank\" rel=\"noopener noreferrer\">weather.gov<\/a>.<\/p>\n<pre>#!\/bin\/bash\r\n# pull weather from weather.gov\r\n# But ONLY IF it has not been pulled recently\r\n# weather is updated once per hour &amp; recommended time to pull is hour+15\r\n# program cron accordingly\r\n# last_update: 20170826 JDN\r\n#\r\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin\r\n\r\n# define minimum time lapse before new pull is permitted\r\ndeclare -i MINAGE=22\r\necho 'Min age' $MINAGE\r\n\r\n# calculate time lapsed since last pull\r\nif [ -f wwraw.xml ];\r\nthen\r\n  declare -i LAPSE=$(( ( $(date +%s) - $(stat wwraw.xml -c %Y)) \/ 60 ))\r\necho 'Lapse' $LAPSE\r\nelse\r\n  declare -i LAPSE=999\r\nfi\r\n\r\n# allow override of command line parameter #1 is --force\r\nif [ -n \"$1\" ]; then declare -i FORCE=1; else declare -i FORCE=0; fi\r\necho force is $FORCE\r\n\r\n#log outside IP\r\necho \"OpenDNS\/Google\" $(dig +short myip.opendns.com @resolver1.opendns.com) \/ $(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com) &gt;wwraw.xme\r\n\r\n# calculate if pull is permitted (boolean)\r\nDOPULL=$(( $LAPSE &gt;= $MINAGE ))\r\necho dopull is $DOPULL\r\n\r\n# test time lapse vs. minimum time lapse to allow pull or override\r\n# Check if file older\r\nif [[ $(($DOPULL + $FORCE)) -gt 0 ]]; then\r\n# debugging message output if pull was performed\r\n  echo \"File was pulled $LAPSE minutes ago. Pulling new weather data\"\r\n\r\n# get surface observations\r\n# file will have date \/ time from weather.gov\r\n  wget -q --output-document=\"wwraw.xml\" http:\/\/w1.weather.gov\/xml\/current_obs\/KFWA.xml\r\n\r\n# mark file with current time to prevent hammering weather.gov\r\n  touch wwraw.xml\r\n\r\n# get weather alerts\r\n  wget -q --output-document=\"walerts.xml\" http:\/\/alerts.weather.gov\/cap\/wwaatmget.php?x=INC003&amp;y=0\r\n\r\nelse\r\n# debugging message output if pull was not performed\r\n  echo \"File was pulled $LAPSE minutes ago. Ignoring request to pull again.\"\r\nfi\r\n\r\n#cleanup\r\nunset FORCE\r\nunset DOPULL\r\nunset MINAGE\r\nunset LAPSE\r\nexit 0\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following script is intended to run on your file server that collects data to distribute to your network. Safety is built in to prevent contacting NOAA weather.gov more than one time per hour.<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[33],"tags":[1616,1617,1618,317,856],"class_list":["post-7050","post","type-post","status-publish","format-standard","hentry","category-general-information","tag-caps","tag-current-weather-feeds","tag-nws-public-alerts","tag-weather","tag-xml"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"jetpack_shortlink":"https:\/\/wp.me\/p3sKnr-1PI","_links":{"self":[{"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=\/wp\/v2\/posts\/7050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7050"}],"version-history":[{"count":1,"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=\/wp\/v2\/posts\/7050\/revisions"}],"predecessor-version":[{"id":7052,"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=\/wp\/v2\/posts\/7050\/revisions\/7052"}],"wp:attachment":[{"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alt-fw.org\/public\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}