FYI PERL script for jonah_weatherstations.tsv
"Todd A. Kopas" <[email protected]>
| Newsgroups | gmane.comp.horde.jonah |
|---|---|
| Message-ID | <[email protected]> |
-- Jonah mailing list Frequently Asked Questions: http://horde.org/faq/ To unsubscribe, mail: [email protected]
create_weatherstations_tsv.pl
(text/plain, 1.7 KB)
#!/usr/local/bin/perl
# WGET LOCATION
$WGET = "/usr/local/bin/wget";
$URL = "http://weather.interceptvector.com/cities/cities.zip";
$UNZIP = "/usr/bin/unzip";
$OUTFILE = "./jonah_weatherstations.tsv";
if ( ! (-f $UNZIP) ) {
print "ERROR: This program requires the unzip command.\n";
exit;
}
# Downloading city list
if ( !(-f $WGET) && ! (-f "./cities.zip") ) {
print "-----------------------------------------------------------\n";
print "ERROR:\n";
print "Please edit the \$WGET variable in \"create_weatherstations_tsv.pl\"\n";
print "or download cities.zip from:\n";
print "\n";
print "\thttp://weather.interceptvector.com/cities/cities.zip\n";
print "\n";
print "and put the \"cities.zip\" file in this directory.\n";
print "-----------------------------------------------------------\n";
exit;
}
elsif ( $flag_cities_zip ) {
system "$UNZIP cities.zip";
start();
exit;
}
elsif ( $WGET ) {
system "$WGET $URL";
system "$UNZIP cities.zip";
start();
exit;
}
sub start {
# Opening jonah_weatherstations.tsv for write.
open (OUT, ">$OUTFILE");
# Getting a list of states including foreign.
@LS = `ls -d *.xml | grep -v index.xml`;
chop @LS;
foreach $state (@LS) {
print "State $state ...";
@CAT = `grep 'city name' $state`;
$state =~ s/.xml$//g;
foreach $cat (@CAT) {
($j1,$city,$j2,$url,) = split (/"/, $cat);
print OUT "$url\t$state\t$city\tgraphics/noradar.gif\t\n";
}
print "Complete.\n";
}
close OUT;
print "./jonah_weatherstations.tsv has been created.\n";
}
README
(text/plain, 451 B)
To create jonah_weatherstations.tsv: 1. Create a new directory. 2. Put ./create_jonahweatherstations_tsv.pl in the new directory. 3. Edit ./create_jonahweatherstations_tsv.pl with the appropriate wget location. 4. Execute ./create_jonahweatherstations_tsv.pl. Here's are some points in the code: $state =~ s/.xml$//g; <-- gets rid of xml suffic to find state ($j1,$city,$j2,$url,) = split (/"/, $cat); <-- parses file using " $j=junk1