#!/usr/local/bin/perl # Get recent hurricane advisories via a URL. The URL passed on the command # line should point to an index of the advisories available. # Copyright (C) 1996 Thomas R. Metcalf # # This software is provided "as is" and is subject to change without # notice. No warranty of any kind is made with regard to this software, # including, but not limited to, the implied warranties of # merchantability and fitness for a particular purpose. The author shall # not be liable for any errors or for direct, indirect, special, # incidental or consequential damages in connection with the furnishing, # performance, or use of this software: use it at your own risk. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # require "/data1/WWW/Tropical/Bin/url_get.pl"; if ($#ARGV != 0) { $url= "http://asp1.sbs.ohio-state.edu:80/text/severe/atltrop/" } else { $url = $ARGV[0]; } # # Initialize # %nummonth = ('JAN',1,'FEB',2,'MAR',3,'APR',4,'MAY',5,'JUN',6,'JUL',7,'AUG',8, 'SEP',9,'OCT',10,'NOV',11,'DEC',12); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime; $mon += 1; @mondays = (31,28,31,30,31,30,31,31,30,31,30,31); if ($year % 4 == 0) { $mondays[1]+=1;} # Look for files which are +3 or -13 hours from now. The -13 gives 3 chances # to read each 6 hour update. The +3 is just for security. $lower = -13; $upper = +3; for ($dhour=$lower; $dhour<=$upper; ++$dhour) { $h = $hour+$dhour; $d = $mday; $m = $mon; $y = $year; while ($h < 0) { $h += 24; $d -= 1; if ($d < 1) { $m -= 1; if ($m < 1) { $m = 12; $y -= 1; #if ($y < 0) {$y=99;} } $d = $mondays[$m-1]; } } while ($h > 24) { $h -= 24; $d += 1; if ($d > $mondays[$m-1]) { $d = 1; $m += 1; if ($m > 12) { $m = 1; $y += 1; #if ($y > 99) {$y=0;} } } } $ly = $y + 1900; $y = $y % 100; if ($h < 10) {$h = "0"."$h";} if ($d < 10) {$d = "0"."$d";} if ($m < 10) {$m = "0"."$m";} if ($y < 10) {$y = "0"."$y";} # First has a 2 digit year $filetest[$dhour-$lower] = $y.$m.$d.$h; # The file names to look for # Next has a 4 digit year $filetest[$dhour-$lower+$upper-$lower+1] = $ly.$m.$d.$h; # The file names to look for # Next has no year at all (but only do this if URL has year) if ($url =~ /\/$ly\//) { #print "URL has YEAR $ly\n"; $filetest[$dhour-$lower+($upper-$lower+1)*2] = $m.$d.$h; # The file names to look for } } # # Get the list of files to grab # if ($url =~ /^ftp\:/) { $contents = `lynx -dump $url`; # Get only lines with URL + year for speed @contents = grep /$url\/{0,1}($ly|$y)/,split("\n",$contents); # @contents = split("\n",$contents); } else { $contents = &url_get($url); @contents = split("\n",$contents); } $fpointer = 0; for ($line=0;$line<=$#contents;++$line) { #$contents[$line] =~ s/\cM//; #$contents[$line] =~ s/\n//; foreach $test (@filetest) { if ($contents[$line] =~ /($url\/{0,1}$test(\-WTPN|)\.(WTNT\d\d|WTPZ\d\d|KNHC|KMIA|PHNL|PHFO|PGTW|KGWC|RODN|HURR|PHNC|ABRF|JOINT_TYPHOON_WARNING_CENTER|NATIONAL_HURRICANE_CENTER|CANADIAN_HURRICANE_CENTRE|Naval_Western_Oceanography_Center|Guam|Miami|Tokyo))/i) { $filelist[$fpointer] = "$1"; ++$fpointer; } if ($contents[$line] =~ /href\s*=\s*\"($test\d*(\.WTNT\d\d|\.WTPZ\d\d|\.KNHC|\.KMIA|\.PHNL|\.PHFO|\.PGTW|\.KGWC|\.RODN|\.HURR|\.PHNC|\.ABRF|\.JOINT_TYPHOON_WARNING_CENTER|\.NATIONAL_HURRICANE_CENTER|\.CANADIAN_HURRICANE_CENTRE|\.Naval_Western_Oceanography_Center|\.Guam|\.Miami|\.Tokyo|[^\"]*))\".*\>/i) { $filelist[$fpointer] = "$1"; ++$fpointer; } if ($contents[$line] =~ /href\s*=\s*\"((WT[A-Z][A-Z]\d\d|TP[A-Z][A-Z]\d\d|WH[A-Z][A-Z]\d\d|WP\d\d\d\dWEB|EP\d\d\d\dWEB|$test\-WTPN|ocean_wx_warnings|eastern_pacific|central_pacific|western_atlantic|western_pacific)\.(WTNT\d\d|WTPZ\d\d|KNHC|KWNH|KMIA|PHNL|PHFO|PGTW|KGWC|RODN|HURR|PHNC|ABRF|JOINT_TYPHOON_WARNING_CENTER|NATIONAL_HURRICANE_CENTER|CANADIAN_HURRICANE_CENTRE|Naval_Western_Oceanography_Center|Guam|Miami|Tokyo|txt|current|next)[^\"]*).*((\d{2,2})\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-(\d{2,4})\s+(\d{2,2})\:\d{2,2})/i) { #$four = $4; #$four =~ s/ / /g; #$month = substr($four,3,3); $year = $7; $month = $6; $day = $5; $hour = $8; $month = $nummonth{"\U$month"}; if (length($month) < 2) {$month = "0".$month;} #$last_modified = substr($four,7,2).$month.substr($four,0,2).substr($four,10,2); $last_modified = $year.$month.$day.$hour; if ($last_modified eq $test) { $filelist[$fpointer] = "$1"; ++$fpointer; } } } } # # Print the files which were found in the directory listing # foreach $fname (@filelist) { if ($fname ne "") { if ($fname =~ /^(http|ftp|gopher|file|wais|telnet|news)\:\/\//i) { # Absolute URL $urlfile = &url_get("$fname","&STDOUT"); } else { # Relative URL $lenurl = length($url); if (substr($url,$lenurl-1,1) eq "/") { $url = substr($url,0,$lenurl-1); } $urlfile = &url_get("$url/$fname","&STDOUT"); } print "\n\cA\n"; } } exit(0);