From eb8d1170197b7146b20035e73fdd4c10ee3e9991 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 7 Apr 2009 10:27:50 +0200 Subject: efa: Put some stuff into subs --- bin/efa | 116 +++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 71 insertions(+), 45 deletions(-) diff --git a/bin/efa b/bin/efa index 8d525ab..04b853b 100755 --- a/bin/efa +++ b/bin/efa @@ -16,12 +16,8 @@ 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; @@ -31,6 +27,73 @@ my $debug = 0; $post{type_origin} = 'stop'; $post{type_destination} = 'stop'; +sub check_ambiguous($) { + my $html = shift; + my $choose_re = qr/Bitte auswählen<\/span>/; + my $select_re = qr/(?[^<]+)<\/option>/gs) { - print "\t$+{choice}\n"; - } +if (check_ambiguous($content)) { + exit(1); } -foreach (split(/ \d+\. Fahrt<\/span>/, $content)) { - unless ($offer) { - $offer++; - next; - } - foreach(split(/\n/)) { - if (/(?[^<]+)<\/span>/) { - push(@{$raw->[$offer-1]}, $+{content}); - } - } - $offer++; -} +$raw = prepare_content($content); if ($debug) { print STDERR "custom post values used in query:\n"; @@ -127,26 +172,7 @@ if ($debug) { } } -for ($offer = 0; exists($raw->[$offer]); $offer++) { - for ($i = 0; @{$raw->[$offer]} >= (($i+1) * $groupsize); $i++) { - $offset = $i * $groupsize; - # If the first field is not a time we've got some additional information. - # Sadly, this script does not parse it yet, so it's ignored - until ($raw->[$offer]->[$offset] =~ /^\d+:\d+$/) { - last unless exists($raw->[$offer]->[++$offset]); - } - $cons->[$offer]->[$i] = { - deptime => $raw->[$offer]->[$offset], - dep => $raw->[$offer]->[$offset+1], - depstop => $raw->[$offer]->[$offset+2], - deptrain => $raw->[$offer]->[$offset+3], - depdest => $raw->[$offer]->[$offset+7], - arrtime => $raw->[$offer]->[$offset+4], - arr => $raw->[$offer]->[$offset+5], - arrstop => $raw->[$offer]->[$offset+6], - }; - } -} +$cons = parse_content($raw); foreach (@$cons) { foreach (@$_) { -- cgit v1.2.3