rivers/new.getstations.pl

29 lines
582 B
Perl
Raw Permalink Normal View History

2016-03-25 07:07:50 +00:00
#!/usr/bin/perl -w
$|=1;
use strict;
use diagnostics;
use DBI;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent("Munin[river_levels_]");
my $base = "http://apps.environment-agency.gov.uk/river-and-sea-levels/";
my $req = HTTP::Request->new(GET => $base . $ARGV[0] . ".aspx");
my $res = $ua->request($req);
if ($res->is_success) {
my @lines = split("\n", $res->content);
foreach my $line (@lines) {
if( $line =~ m~href="\?stationId=(\d+)" alt="([^"]+)"~ ) {
my $stationId = $1;
my $name = $2;
print $stationId . " ";
}
}
} else {
die "failed!";
}