Hi All
I travel along the M62 to get to work and the traffic is a bit of a pain. I wrote this simple LWP script to grab traffic reports from RAC website and pick out those of interest to me.
The code does rely on the structure of the web page not changing which is not the best solution, so if any Monks out there know of a structured source for traffic reports, i'd like to hear from you.
Regards
Orthanc
#!/usr/bin/perl use LWP::Simple; $| = 1; $url = "http://www.rac.co.uk/scripts/traffic.htt?area=5"; $res_okay = 1; $req_motorway = ($ARGV[0]) ? $ARGV[0] : "M62|A58"; $req_motorway =~ s/\,/\|/g; $clear = `clear`; print "$clear"; print "Getting reports for $req_motorway\n\n"; @html=get("$url"); foreach (@html) { $html .= $_; } @htmllines = split(/\n/,$html); %motorways = (); foreach (@htmllines) { if(/bodytextonehead/) { m/bodytextonehead\"\>(.*)\</i; $mway = "$1|$i"; } if(/bodytexttwo/ && /\|/) { m/bodytexttwo\"\>\| (.*) \|\</i; $motorways{$mway}{'time'} = $1; m/ltnbaro_0(\d+)\.gif/i; $motorways{$mway}{'baro'} = $1; } if(/bodytexttwofade/) { m/bodytexttwofade\"\>(.*)\<\/FONT/i; $motorways{$mway}{'report'} = $1; $motorways{$mway}{'report'} =~ s/'/\'/g; $motorways{$mway}{'report'} =~ s/&/\&/g; } $i++; } foreach $key (keys %motorways) { ($mway,$x) = split(/\|/,$key); next if($mway !~ m/$req_motorway/); print "$mway\n"; print "Time: $motorways{$key}{'time'}\n"; print "Baro: $motorways{$key}{'baro'}\n"; print "Report: $motorways{$key}{'report'}\n"; } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Road Traffic Check
by ar0n (Priest) on Jun 20, 2000 at 01:00 UTC | |
by merlyn (Sage) on Jun 20, 2000 at 01:22 UTC | |
|
RE: Road Traffic Check
by Odud (Pilgrim) on Jun 20, 2000 at 23:17 UTC | |
by orthanc (Monk) on Jun 21, 2000 at 12:19 UTC |