WWW::Oxontime - live Oxford bus departures from Oxontime
use WWW::Oxontime qw/stops_for_route departures_for_stop nextbus_from_to :constants/; my @stops_on_8_outbound = stops_for_route 15957; my $queens_lane = $stops_on_8_outbound[2]->{stopId}; my @from_queens_lane = departures_for_stop $queens_lane; for my $entry (@from_queens_lane) { say $entry->{service}, ' towards ', $entry->{destination}, ' departs at ', $entry->{departs}; } my @from_city_centre_to_headington_campus = nextbus_from_to NEXTBUS_FROM_CITY_CENTRE, 'Headington Campus'; for my $line (@from_city_centre_to_headington_campus) { my ($from, $service, $departs_in, $departs_in_mins) = @$line; say "Bus $service leaves from $from in $departs_in"; }
This module wraps http://www.oxontime.com to provide live bus departures in Oxford.
Two methods can be exported (none by default):
Given a route ID (these can be obtained by inspecting the homepage of Oxontime), returns in list context a list of hashrefs having the keys stopName (name of stop) and stopId (ID of stop, suitable for passing to departures_for_stop). In scalar context, an arrayref containing this list is returned.
stopName
stopId
departures_for_stop
Given a stop ID (these can be obtained by inspecting the homepage of Oxontime or by calling stops_for_route), returns in list context a list of hashrefs having the keys service (name of service and company that runs it), destination (where the service is finishing) and departs (Time::Piece object representing the time when the service departs). In scalar context, an arrayref containing the list is returned.
stops_for_route
service
destination
departs
Note that departs is in the time zone of Oxford, but Time::Piece interprets it as being in local time. If local time is different from time in Oxford, this needs to be taken into account.
Given a place to start from and a place to arrive at this method returns a list of the next buses to serve that route. $from must be one of the 8 provided constants:
NEXTBUS_FROM_HEADINGTON_CAMPUS NEXTBUS_FROM_HARCOURT_HILL NEXTBUS_FROM_MARSTON_ROAD NEXTBUS_FROM_WHEATLEY_CAMPUS NEXTBUS_FROM_CRESCENT_HALL NEXTBUS_FROM_PAUL_KENT_HALL NEXTBUS_FROM_SLADE_PARK NEXTBUS_FROM_CITY_CENTRE
whereas $to is the name of an important station.
This function calls the Nextbus service at http://nextbus.brookes.ac.uk/. It is unclear what values for $to are implemented by Nextbus; it is probably best to inspect the website to see what destinations are available.
Marius Gavrilescu, <marius@ieval.ro>
Copyright (C) 2017 by Marius Gavrilescu
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.26.1 or, at your option, any later version of Perl 5 you may have available.
To install WWW::Oxontime, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Oxontime
CPAN shell
perl -MCPAN -e shell install WWW::Oxontime
For more information on module installation, please visit the detailed CPAN module installation guide.