#!/usr/bin/env perl ## Copyright © 2009 by Daniel Friesel ## License: WTFPL use strict; use warnings; use 5.010; use encoding 'utf8'; use Getopt::Long; use WWW::Mechanize; my $firsturl = 'http://efa.vrr.de/vrr/XSLT_TRIP_REQUEST2?language=de&itdLPxx_transpCompany=vrr'; my $posturl = 'http://efa.vrr.de/vrr/XSLT_TRIP_REQUEST2'; my $content; my %post; my $www = WWW::Mechanize->new( autocheck => 1, ); my $offer = 0; my $i = 0; my $raw; my $cons; my $groupsize = 8; my $offset; my (@from, @to, @via); my ($time, $time_depart, $time_arrive); my $date; my $restrict; my $debug = 0; $post{type_origin} = 'stop'; $post{type_destination} = 'stop'; GetOptions( 'arrive=s' => \$time_arrive, 'date=s' => \$date, 'debug' => \$debug, 'depart=s' => \$time_depart, 'from=s{2}' => \@from, 'post=s' => \%post, 'restrict=s' => \$restrict, 'time=s' => \$time, 'to=s{2}' => \@to, 'via=s{2}' => \@via, ); unless (@to == 2 and @from == 2) { print STDERR "Usage: efa --from --to [other options]\n"; exit(1); } @post{'place_origin','name_origin'} = @from; @post{'place_destination','name_destination'} = @to; if (@via == 2) { @post{'place_via','name_via'} = @via; } if ($time_arrive) { $time = $time_arrive; $post{itdTripDateTimeDepArr} = 'arr'; } elsif ($time_depart) { $time = $time_depart; $post{itdTripDateTimeDepArr} = 'dep'; } if ($time) { @post{'itdTimeHour','itdTimeMinute'} = split(/:/, $time); } if ($date) { @post{'itdDateDay','itdDateMonth','itdDateYear'} = split(/\./, $date); } if ($restrict) { given ($restrict) { when('local') { $post{lineRestriction} = 403 } when('ic') { $post{lineRestriction} = 401 } when('ice') { $post{lineRestriction} = 400 } when(/\d+/) { $post{lineRestriction} = $restrict } default { print STDERR "--restrict usage: local / ic / ice\n"; } } } $www->get($firsturl); $www->submit_form( form_name => 'jp', fields => \%post, ); $content = $www->content; # ambiguous input foreach (split(/Bitte auswählen<\/span>/s, $content)) { if (/