Blog Fiasco

October 19, 2010

Building dial information for the radar page

Filed under: Linux,The Internet — Tags: , , — bcotton @ 8:26 am

I thought building the dial (adjacent radar sites) data for my mobile radar site would be a tedious and entirely painful process.  As it turns out, it really wasn’t that difficult.  I knew the data was out there in some form, if you visit any of the radar sites on the NWS website, you get a nice dial in the upper-left part of the screen, but I couldn’t find a good text file with that information.  Just when I was about to stat copying it by hand, I thought “maybe this is parseable”.

It turns out that the page is parseable, but it gets ugly at times.  To get a list of all the sites, I grabbed a file from Unisys.  I could extract the site, city, and state from there, so then all I needed was to grab the 8 (or fewer surrounding sites) and dump them all into a Perl hash.  So I wrote a bit of code to do just that.  It’s ugly, but it’s an example of what you can do when you really, really don’t want to do something by hand:

@sites = <STDIN>;

foreach $site ( @sites ) {
 $city = substr $site, 0, 14;
 $city =~ s/\s{2,}/ /g;
 $state = substr $site, 16, 2;
 $id = substr $site, 24, 3;

 print "  '$id' => ['$city, $state', ";

 $littleID = lc($id);
 $htmlCrap = `wget http://radar.weather.gov/radar.php?rid=$littleID -o /dev/null -O - | grep adjacent`;
 foreach ( split(/<\/td>/, $htmlCrap, 9) ) {
 unless ( $_ =~ /$id/ ) {
 if ( $_ =~ m /newpage/ ) {
 $dialid = $_;
 $dialid =~ s/.*newpage\(\'(...)'.*/\1/g;
 chomp ($dialid);
 $dialid =~ tr/a-z/A-Z/;
 print "\'$dialid\', ";
 } else {
 print "\'\',    ";
 }
 }
 }
 print "],\n";
}

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress