Hi Fellow Monks
I'm back again with my new road traffic script
I've found that the RAC provide the best traffic reports so i've used their site as feed.
The script is easily modifiable for those in different regions, sorry to all the monks who live abroad :)
#!/usr/bin/perl -w
use LWP::Simple;
use strict;
use vars qw( $url $want @html );
# URL - Change north to whatever region you require
# north, greater_london, scotland, southern_england,
# midlands, wales
$url = 'http://www.rac.co.uk/check_traffic/north/?&nav&view=Standar
+d';
$want = 'M62|A58|A629';
# See if we are looking for different roads
$want = ($ARGV[0]) ? $ARGV[0] : $want;
$want =~ s/\,/\|/g;
print "Getting reports for $want\n";
# Get the information from RAC
@html = split(/\n/,get("$url"));
# Did it barf?
if($#html == -1)
{
print STDERR "RAC Site unavailable\n";
exit;
}
# Parse
foreach (@html) {
next unless(/Incident ID/);
next unless(/$want/);
s/<[^>]*>//g; # Remove html
s/(\w+)/\u\L$1/g; # Remove nasty caps
## Nice of the RAC to conveniently put pipes in :)
my ($area, $time, $report) = split(/\|/);
$time =~ s/ //g; # Tidy up the time
print "\n$area ($time)\n"; # Spit it out
print "$report\n";
}
exit;
I even managed strict and warnings on!
Enjoy, Orthanc