{"id":356,"date":"2020-03-30T20:11:00","date_gmt":"2020-03-31T01:11:00","guid":{"rendered":"https:\/\/sundrysites.com\/?page_id=356"},"modified":"2020-03-30T20:11:00","modified_gmt":"2020-03-31T01:11:00","slug":"get-weather-info","status":"publish","type":"page","link":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/","title":{"rendered":"Get Weather Info"},"content":{"rendered":"\n<p>This Perl program queries the weather conditions at KDAY (Dayton, Ohio).&nbsp; It parses the result, creating an HCA-friendly file that can be read into HCA and recorded or otherwise acted upon.<\/p>\n\n\n\n<p>use warnings;<br>use strict;<br>use LWP::Simple;&nbsp; # supplies &#8216;get&#8217; function<br>use XML::Simple;&nbsp; # supplies xml parsing functions<br>use Data::Dumper;&nbsp; # used for diag<\/p>\n\n\n\n<p># major definitions<br>my $outfile = &#8220;noaa-wx.txt&#8221;;<br>my $url = &#8220;http:\/\/www.weather.gov\/xml\/current_obs\/KDAY.xml&#8221;;<br>my $page = &#8220;&#8221;;<br>my $xmldata = &#8220;&#8221;;<br>my $outln = &#8220;&#8221;;<br># definintions for history file<br>my $histfile = &#8220;&#8221;;<br>my $histln = &#8220;&#8221;;<br>my $yearnumber = &#8220;&#8221;;<br>my $monthnumber = &#8220;&#8221;;<br>my $visibility_xx = &#8220;&#8221;;<\/p>\n\n\n\n<p># define simple fields that go into csv record<br>my $year_2 = &#8220;2008&#8221;;<br>my $month_3 = &#8220;01&#8221;;<br>my $date_4 = &#8220;01&#8221;;<br>my $hour_5 = &#8220;12&#8221;;<br>my $min_6 = &#8220;00&#8221;;<br>my $sec_7 = &#8220;00&#8221;;<br>my $wind_sp_8 = &#8220;0&#8221;;<br>my $wind_gust_9 = &#8220;0&#8221;;<br>my $wind_dir_10 = &#8220;000&#8221;;<br>my $rel_humid_12 = &#8220;00&#8221;;<br>my $temp_f_14 = &#8220;0&#8221;;<br>my $pressure_15 = &#8220;0&#8221;;<br>my $weather_19 = &#8220;0&#8221;;<br>my $wind_chill_29 = &#8220;0&#8221;;<br>my $heat_index_31 = &#8220;0&#8221;;<br>my $dewpoint_32 = &#8220;0&#8221;;<\/p>\n\n\n\n<p># define working areas for more complicated fields<br>my $work_date = &#8220;&#8221;;<br>my $work_weather = &#8220;&#8221;;<br>my @date_toks;<br>my $work_month;<br>my @work_time;<\/p>\n\n\n\n<p>$page = get ($url);&nbsp;&nbsp; # get xml record from NOAA<\/p>\n\n\n\n<p>$xmldata = XMLin($page);&nbsp; # give record to xml parser<\/p>\n\n\n\n<p># print Dumper($xmldata);&nbsp; # for diags<\/p>\n\n\n\n<p># pull the easy values out of the xml record<br>$wind_sp_8 = $xmldata-&gt;{wind_mph};<br>$wind_gust_9 = 0;&nbsp; #no longer part of metar<br>$wind_dir_10 = $xmldata-&gt;{wind_degrees};<br>$rel_humid_12 = $xmldata-&gt;{relative_humidity};<br>$temp_f_14 = $xmldata-&gt;{temp_f};<br>$pressure_15 = $xmldata-&gt;{pressure_in};<br>$wind_chill_29 = 0; #no longer part of metar<br>$heat_index_31 = 0;&nbsp; #no longer part of metar<br>$dewpoint_32 = $xmldata-&gt;{dewpoint_f};<br>$visibility_xx = $xmldata-&gt;{visibility_mi};<\/p>\n\n\n\n<p># split out the date<br>$work_date = $xmldata-&gt;{observation_time_rfc822};<br>@date_toks = split(\/\\s+\/, $work_date);&nbsp;&nbsp; # tokenize on white space<br>$year_2 = $date_toks[3];<br>$work_month = $date_toks[2];&nbsp; # assign number to month name, crudely done<br>if ($work_month eq &#8220;Jan&#8221;) {$month_3 = &#8220;1&#8221;};<br>if ($work_month eq &#8220;Feb&#8221;) {$month_3 = &#8220;2&#8221;};<br>if ($work_month eq &#8220;Mar&#8221;) {$month_3 = &#8220;3&#8221;};<br>if ($work_month eq &#8220;Apr&#8221;) {$month_3 = &#8220;4&#8221;};<br>if ($work_month eq &#8220;May&#8221;) {$month_3 = &#8220;5&#8221;};<br>if ($work_month eq &#8220;Jun&#8221;) {$month_3 = &#8220;6&#8221;};<br>if ($work_month eq &#8220;Jul&#8221;) {$month_3 = &#8220;7&#8221;};<br>if ($work_month eq &#8220;Aug&#8221;) {$month_3 = &#8220;8&#8221;};<br>if ($work_month eq &#8220;Sep&#8221;) {$month_3 = &#8220;9&#8221;};<br>if ($work_month eq &#8220;Oct&#8221;) {$month_3 = &#8220;10&#8221;};<br>if ($work_month eq &#8220;Nov&#8221;) {$month_3 = &#8220;11&#8221;};<br>if ($work_month eq &#8220;Dec&#8221;) {$month_3 = &#8220;12&#8221;};<\/p>\n\n\n\n<p>$date_4 = $date_toks[1];<\/p>\n\n\n\n<p># split out time<br>@work_time = split(\/:\/, $date_toks[4]);&nbsp; # get and split time field by colons<br>$hour_5 = $work_time[0];<br>$min_6 = $work_time[1];<br>$sec_7 = $work_time[2];<\/p>\n\n\n\n<p>$weather_19 = $xmldata-&gt;{weather};&nbsp; # for now just grab field<\/p>\n\n\n\n<p># now that the fields are assembled, write them out to disk<br># first write out the hca import data file<br>open OUTPUT, &#8220;&gt; $outfile&#8221; or die &#8220;Output file open error: $!&#8221;;<\/p>\n\n\n\n<p># create each line in hca file import format<br># including whatever you want hca to see<br>$outln = &#8220;noaaouttemp&#8221; . &#8220;=&#8221; . $temp_f_14 . &#8220;\\n&#8221;;<br>print OUTPUT $outln;<br>$outln = &#8220;noaaoutrh&#8221; . &#8220;=&#8221; . $rel_humid_12 . &#8220;\\n&#8221;;<br>print OUTPUT $outln;<\/p>\n\n\n\n<p># create and write the separate history file<br>$yearnumber = $year_2;&nbsp;&nbsp;&nbsp; # grab current year from noaa<br>$monthnumber = $month_3;&nbsp;&nbsp; # grab current month from noaa<br>if ((length $monthnumber) == 1) {$monthnumber = &#8220;0&#8221; . $monthnumber};<br>$histfile = &#8220;yswxhist&#8221; . $yearnumber . $monthnumber . &#8220;\\.&#8221; . &#8220;csv&#8221;;&nbsp; # use noaa year and month to create file name<br>open HIST, &#8220;&gt;&gt; $histfile&#8221; or die &#8220;History file open error: $!&#8221;;<br># if first hour of the day, put put a separator line<br>if ($hour_5 eq &#8220;00&#8221;)<br>{<br>$histln = &#8220;yy,mm,dd,hh,mm,tf,wc,hi,weather,ws,wg,wd,ba,rh,dp,vs\\n&#8221;;<br>print HIST $histln;<br>}<\/p>\n\n\n\n<p># create record in csv format, my choice of fields<br>$histln = &#8220;$year_2,$month_3,$date_4,$hour_5,$min_6,$temp_f_14,$wind_chill_29,$heat_index_31,$weather_19,$wind_sp_8,$wind_gust_9,$wind_dir_10,$pressure_15,$rel_humid_12,$dewpoint_32,$visibility_xx \\n&#8221; ;<br># put record out to disk, appending the record<\/p>\n\n\n\n<p>print HIST $histln;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This Perl program queries the weather conditions at KDAY (Dayton, Ohio).&nbsp; It parses the result, creating an HCA-friendly file that can be read into HCA and recorded or otherwise acted upon. use warnings;use strict;use LWP::Simple;&nbsp; # supplies &#8216;get&#8217; functionuse XML::Simple;&nbsp; # supplies xml parsing functionsuse Data::Dumper;&nbsp; # used for diag # major definitionsmy $outfile = &hellip; <a href=\"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Get Weather Info<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":352,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-356","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Get Weather Info - Sundrysites<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Weather Info - Sundrysites\" \/>\n<meta property=\"og:description\" content=\"This Perl program queries the weather conditions at KDAY (Dayton, Ohio).&nbsp; It parses the result, creating an HCA-friendly file that can be read into HCA and recorded or otherwise acted upon. use warnings;use strict;use LWP::Simple;&nbsp; # supplies &#8216;get&#8217; functionuse XML::Simple;&nbsp; # supplies xml parsing functionsuse Data::Dumper;&nbsp; # used for diag # major definitionsmy $outfile = &hellip; Continue reading Get Weather Info &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/\" \/>\n<meta property=\"og:site_name\" content=\"Sundrysites\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/get-weather-info\\\/\",\"url\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/get-weather-info\\\/\",\"name\":\"Get Weather Info - Sundrysites\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#website\"},\"datePublished\":\"2020-03-31T01:11:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/get-weather-info\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/get-weather-info\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/get-weather-info\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Home Info\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Arduino Projects\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Perl Programs\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Get Weather Info\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#website\",\"url\":\"https:\\\/\\\/sundrysites.com\\\/\",\"name\":\"Sundrysites\",\"description\":\"As In Various and Sundry\",\"publisher\":{\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#\\\/schema\\\/person\\\/1e11ce6af1587a3431e57dfc0797ab61\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sundrysites.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#\\\/schema\\\/person\\\/1e11ce6af1587a3431e57dfc0797ab61\",\"name\":\"Wayne Gulden\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\",\"caption\":\"Wayne Gulden\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\"},\"sameAs\":[\"https:\\\/\\\/sundrysites.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get Weather Info - Sundrysites","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/","og_locale":"en_US","og_type":"article","og_title":"Get Weather Info - Sundrysites","og_description":"This Perl program queries the weather conditions at KDAY (Dayton, Ohio).&nbsp; It parses the result, creating an HCA-friendly file that can be read into HCA and recorded or otherwise acted upon. use warnings;use strict;use LWP::Simple;&nbsp; # supplies &#8216;get&#8217; functionuse XML::Simple;&nbsp; # supplies xml parsing functionsuse Data::Dumper;&nbsp; # used for diag # major definitionsmy $outfile = &hellip; Continue reading Get Weather Info &rarr;","og_url":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/","og_site_name":"Sundrysites","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/","url":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/","name":"Get Weather Info - Sundrysites","isPartOf":{"@id":"https:\/\/sundrysites.com\/#website"},"datePublished":"2020-03-31T01:11:00+00:00","breadcrumb":{"@id":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/get-weather-info\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sundrysites.com\/"},{"@type":"ListItem","position":2,"name":"Home Info","item":"https:\/\/sundrysites.com\/index.php\/home-info\/"},{"@type":"ListItem","position":3,"name":"Arduino Projects","item":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/"},{"@type":"ListItem","position":4,"name":"Perl Programs","item":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/"},{"@type":"ListItem","position":5,"name":"Get Weather Info"}]},{"@type":"WebSite","@id":"https:\/\/sundrysites.com\/#website","url":"https:\/\/sundrysites.com\/","name":"Sundrysites","description":"As In Various and Sundry","publisher":{"@id":"https:\/\/sundrysites.com\/#\/schema\/person\/1e11ce6af1587a3431e57dfc0797ab61"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sundrysites.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/sundrysites.com\/#\/schema\/person\/1e11ce6af1587a3431e57dfc0797ab61","name":"Wayne Gulden","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g","caption":"Wayne Gulden"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g"},"sameAs":["https:\/\/sundrysites.com"]}]}},"_links":{"self":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/comments?post=356"}],"version-history":[{"count":1,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/356\/revisions"}],"predecessor-version":[{"id":357,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/356\/revisions\/357"}],"up":[{"embeddable":true,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/352"}],"wp:attachment":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/media?parent=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}