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


In reply to New Road Traffic Reports by orthanc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.