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

Replies are listed 'Best First'.
RE: New Road Traffic Reports
by BigJoe (Curate) on Nov 15, 2000 at 02:36 UTC
    This would be really great if it worked in the states. :-)

    --BigJoe

    Learn patience, you must.
    Young PerlMonk, craves Not these things.
    Use the source Luke.
      Well seeing as it was written for UK data, throwing a reverse() in there should do the trick! ;-)
Re: New Road Traffic Reports
by a (Friar) on Nov 19, 2000 at 10:30 UTC
    Well, it does work in the US, it just isn't very helpful. Unless I'm driving through HUMBERSIDE.

    2 points: change the "RAC site unavailable" to use $url (sure it won't bite you, but if you cut and paste and leave the +d in ...), what the heck you have the info.
    Make the next unless /$want/ a /$want/i so:
    humberside
    will work too (not just Humberside).

    Doubt the US will ever have such pleasant traffic reporting.

    a