ability to configure age and reduction card
This commit is contained in:
parent
f471040455
commit
ae7a28ae04
3 changed files with 47 additions and 12 deletions
|
|
@ -18,7 +18,9 @@
|
|||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
from weboob.tools.value import Value
|
||||
from weboob.capabilities.travel import ICapTravel, Station, Departure
|
||||
from weboob.capabilities import UserError
|
||||
|
||||
|
|
@ -35,6 +37,35 @@ class VoyagesSNCFBackend(BaseBackend, ICapTravel):
|
|||
EMAIL = 'romain@weboob.org'
|
||||
LICENSE = 'AGPLv3+'
|
||||
VERSION = '0.h'
|
||||
CONFIG = BackendConfig(Value('age', label='Passenger age', default='ADULT',
|
||||
choices=OrderedDict((('ADULT', '26-59 ans'),
|
||||
('SENIOR', '60 et +'),
|
||||
('YOUNG', '12-25 ans'),
|
||||
('CHILD_UNDER_FOUR', '0-3 ans'),
|
||||
('CHILDREN', '4-11 ans')))),
|
||||
Value('card', label='Passenger card', default='default',
|
||||
choices=OrderedDict((('default', u'Pas de carte'),
|
||||
('YOUNG', u'Carte 12-25 / 12-30'),
|
||||
('YOUNGS', u'Carte Jeune'),
|
||||
('ESCA', u'Carte Escapades'),
|
||||
('WEEKE', u'Carte Week-end'),
|
||||
('FQ2ND', u'Abo Fréquence 2e'),
|
||||
('FQ1ST', u'Abo Fréquence 1e'),
|
||||
('FF2ND', u'Abo Forfait 2e'),
|
||||
('FF1ST', u'Abo Forfait 1e'),
|
||||
('ACCWE', u'Accompagnant Carte Week-end'),
|
||||
('ACCCHD', u'Accompagnant Carte Enfant+'),
|
||||
('ENFAM', u'Carte Enfant Famille'),
|
||||
('FAM30', u'Carte Familles Nombreuses 30%'),
|
||||
('FAM40', u'Carte Familles Nombreuses 40%'),
|
||||
('FAM50', u'Carte Familles Nombreuses 50%'),
|
||||
('FAM75', u'Carte Familles Nombreuses 75%'),
|
||||
('MI2ND', u'Carte Militaire 2e'),
|
||||
('MI1ST', u'Carte Militaire 1e'),
|
||||
('MIFAM', u'Carte Famille Militaire'),
|
||||
('THBIZ', u'Thalys ThePass Business'),
|
||||
('THPREM', u'Thalys ThePass Premium'),
|
||||
('THWE', u'Thalys ThePass Weekend')))))
|
||||
|
||||
BROWSER = VoyagesSNCFBrowser
|
||||
STATIONS = []
|
||||
|
|
@ -65,7 +96,9 @@ class VoyagesSNCFBackend(BaseBackend, ICapTravel):
|
|||
raise UserError('Unknown station')
|
||||
|
||||
with self.browser:
|
||||
for i, d in enumerate(self.browser.iter_departures(station, arrival, date)):
|
||||
for i, d in enumerate(self.browser.iter_departures(station, arrival, date,
|
||||
self.config['age'].get(),
|
||||
self.config['card'].get())):
|
||||
departure = Departure(i, d['type'], d['time'])
|
||||
departure.departure_station = d['departure']
|
||||
departure.arrival_station = d['arrival']
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ class VoyagesSNCFBrowser(BaseBrowser):
|
|||
self.location('/completion/VSC/FR/fr/cityList.js')
|
||||
return self.page.get_stations()
|
||||
|
||||
def iter_departures(self, departure, arrival, date):
|
||||
def iter_departures(self, departure, arrival, date, age, card):
|
||||
self.location('/billet-train')
|
||||
self.page.search(departure, arrival, date)
|
||||
self.page.search(departure, arrival, date, age, card)
|
||||
|
||||
return self.page.iter_results()
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class CitiesPage(BasePage):
|
|||
return result['CITIES']
|
||||
|
||||
class SearchPage(BasePage):
|
||||
def search(self, departure, arrival, date):
|
||||
def search(self, departure, arrival, date, age, card):
|
||||
self.browser.select_form(name='saisie')
|
||||
self.browser['ORIGIN_CITY'] = departure.encode(self.browser.ENCODING)
|
||||
self.browser['DESTINATION_CITY'] = arrival.encode(self.browser.ENCODING)
|
||||
|
|
@ -47,7 +47,8 @@ class SearchPage(BasePage):
|
|||
|
||||
self.browser['OUTWARD_DATE'] = date.strftime('%d/%m/%y')
|
||||
self.browser['OUTWARD_TIME'] = [str(date.hour + 1)]
|
||||
self.browser['PASSENGER_1'] = ['ADULT']
|
||||
self.browser['PASSENGER_1'] = [age]
|
||||
self.browser['PASSENGER_1_CARD'] = [card]
|
||||
self.browser.controls.append(ClientForm.TextControl('text', 'nbAnimalsForTravel', {'value': ''}))
|
||||
self.browser['nbAnimalsForTravel'] = '0'
|
||||
self.browser.submit()
|
||||
|
|
@ -65,8 +66,9 @@ class SearchInProgressPage(BasePage):
|
|||
self.browser.location(link.attrib['href'])
|
||||
|
||||
class ResultsPage(BasePage):
|
||||
def get_value(self, div, name):
|
||||
p = div.cssselect(name)[0]
|
||||
def get_value(self, div, name, last=False):
|
||||
i = -1 if last else 0
|
||||
p = div.cssselect(name)[i]
|
||||
sub = p.find('p')
|
||||
if sub is not None:
|
||||
txt = sub.tail.strip()
|
||||
|
|
@ -77,8 +79,8 @@ class ResultsPage(BasePage):
|
|||
|
||||
return unicode(self.parser.tocleanstring(p))
|
||||
|
||||
def parse_hour(self, div, name):
|
||||
txt = self.get_value(div, name)
|
||||
def parse_hour(self, div, name, last=False):
|
||||
txt = self.get_value(div, name, last)
|
||||
hour, minute = map(int, txt.split('h'))
|
||||
return time(hour, minute)
|
||||
|
||||
|
|
@ -96,8 +98,8 @@ class ResultsPage(BasePage):
|
|||
yield {'type': self.get_value(div, 'div.transporteur-txt'),
|
||||
'time': self.parse_hour(div, 'div.departure div.hour'),
|
||||
'departure': self.get_value(div, 'div.departure div.station'),
|
||||
'arrival': self.get_value(div, 'div.arrival div.station'),
|
||||
'arrival_time': self.parse_hour(div, 'div.arrival div.hour'),
|
||||
'arrival': self.get_value(div, 'div.arrival div.station', last=True),
|
||||
'arrival_time': self.parse_hour(div, 'div.arrival div.hour', last=True),
|
||||
'price': price,
|
||||
'currency': currency,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue