split-route.pl OXF BHM 2014-05-16 17:00
+=head1 BUGS
+
+Sometimes traintimes.org.uk returns 500 errors. These are not caught, and so
+cause the script to fail.
+
=cut
use WWW::Mechanize;
pod2usage( "Invalid number of arguments passed (use --help for more details)" );
}
+# Time everything
+my $timer = time;
+
my ( $src_in, $dest_in, $date, $depart ) = @ARGV;
my $mech = WWW::Mechanize->new();
}
printf "Total price: £%.2f\n", $sum;
printf "Direct price: £%.2f\n", $route->{price};
+printf "[calculated in %ds]\n", ( time - $timer );
##
## functions below here
my $tree = HTML::TreeBuilder->new_from_content( $mech->content );
my $first_stop = $tree->look_down( '_tag', 'li', 'id', 'result0' );
+
+ # check if it's direct or not:
+ my $change_link = $first_stop->look_down('_tag', 'a', 'class', 'change_link');
+ if( $change_link ){
+ die "Error: first train returned by $url is not direct!\n";
+ }
my $details_url = $first_stop->look_down( '_tag', 'a', 'class', 'calling_link' )->attr('href');
my $ticket_type = $first_stop->look_down( '_tag', 'span', 'class', 'fare-type tooltip')->look_down('_tag', 'a')->as_text;
my $ticket_price = ( $first_stop->look_down( '_tag', 'label' ) )[0]->as_text;