ICapTravel.iter_station_departures can take an optional 'arival_station' argument

This commit is contained in:
Romain Bignon 2010-03-23 23:44:29 +01:00
commit 0f92967357
4 changed files with 13 additions and 8 deletions

View file

@ -24,6 +24,10 @@ from weboob.capabilities.travel import ICapTravel, Station, Departure
from .browser import CanalTP from .browser import CanalTP
class CanalTPBackend(Backend, ICapTravel): class CanalTPBackend(Backend, ICapTravel):
MAINTAINER = 'Romain Bignon'
EMAIL = 'romain@peerfuse.org'
VERSION = '1.0'
def __init__(self, weboob): def __init__(self, weboob):
Backend.__init__(self, weboob) Backend.__init__(self, weboob)
@ -32,9 +36,9 @@ class CanalTPBackend(Backend, ICapTravel):
for _id, name in canaltp.iter_station_search(pattern): for _id, name in canaltp.iter_station_search(pattern):
yield Station(_id, name) yield Station(_id, name)
def iter_station_departures(self, station_id): def iter_station_departures(self, station_id, arrival_id=None):
canaltp = CanalTP() canaltp = CanalTP()
for i, d in enumerate(canaltp.iter_station_departures(station_id)): for i, d in enumerate(canaltp.iter_station_departures(station_id, arrival_id)):
departure = Departure(i, d['type'], d['time']) departure = Departure(i, d['type'], d['time'])
departure.departure_station = d['departure'] departure.departure_station = d['departure']
departure.arrival_station = d['arrival'] departure.arrival_station = d['arrival']

View file

@ -40,7 +40,7 @@ class CanalTP(Browser):
else: else:
yield _id, toUnicode(name) yield _id, toUnicode(name)
def iter_station_departures(self, station_id): def iter_station_departures(self, station_id, arrival_id=None):
result = self.openurl(u"http://widget.canaltp.fr/Prochains_departs_15122009/dev/index.php?gare=%s" % unicode(station_id)).read() result = self.openurl(u"http://widget.canaltp.fr/Prochains_departs_15122009/dev/index.php?gare=%s" % unicode(station_id)).read()
result = result result = result
departure = '' departure = ''

View file

@ -30,11 +30,12 @@ class ICapTravel:
""" """
raise NotImplementedError() raise NotImplementedError()
def iter_station_departures(self, station_id): def iter_station_departures(self, station_id, arrival_id):
""" """
Iterate on departures. Iterate on departures.
@param station_id [id] the station id @param station_id [id] the station id
@param arrival_id [id] optionnal arrival station id
@return [iter] result of Departure objects @return [iter] result of Departure objects
""" """
raise NotImplementedError() raise NotImplementedError()

View file

@ -74,8 +74,8 @@ class Application(BaseApplication):
def command_help(self): def command_help(self):
print 'Available commands are:' print 'Available commands are:'
print ' stations <pattern> Search stations' print ' stations <pattern> Search stations'
print ' departures <station> List all departures on a special station' print ' departures <station> [arrival] List all departures on a special station'
def command_stations(self, pattern): def command_stations(self, pattern):
print ".--------------------------------.---------------------------------------------." print ".--------------------------------.---------------------------------------------."
@ -90,13 +90,13 @@ class Application(BaseApplication):
print "| %3d stations listed |" % count print "| %3d stations listed |" % count
print "'------------------------------------------------------------------------------'" print "'------------------------------------------------------------------------------'"
def command_departures(self, station): def command_departures(self, station, arrival_station=None):
print ".-----.-----------.-------.-----------------------.-------.--------------------." print ".-----.-----------.-------.-----------------------.-------.--------------------."
print "| ID | Type | Time | Arrival | Late | Info |" print "| ID | Type | Time | Arrival | Late | Info |"
print "+-----+-----------+-------+-----------------------+-------+--------------------+" print "+-----+-----------+-------+-----------------------+-------+--------------------+"
count = 0 count = 0
for name, backend, in self.weboob.iter_backends(): for name, backend, in self.weboob.iter_backends():
for departure in backend.iter_station_departures(station): for departure in backend.iter_station_departures(station, arrival_station):
print u"| %3d | %-9s | %5s | %-21s | %5s | %-18s |" % (departure.id, print u"| %3d | %-9s | %5s | %-21s | %5s | %-18s |" % (departure.id,
departure.type, departure.type,
departure.time.strftime("%H:%M"), departure.time.strftime("%H:%M"),