diff --git a/modules/champslibres/backend.py b/modules/champslibres/backend.py index 74491024..ddb64602 100644 --- a/modules/champslibres/backend.py +++ b/modules/champslibres/backend.py @@ -35,7 +35,7 @@ class ChampslibresBackend(BaseBackend, ICapBook): VERSION = '0.c' DESCRIPTION = 'Champs Libres (Rennes) Library' LICENSE = 'AGPLv3+' - CONFIG = BackendConfig(Value('login', label='Account ID', regexp='^\d{1,15}|$'), + CONFIG = BackendConfig(Value('login', label='Account ID', regexp='^\d{1,15}|$'), ValueBackendPassword('password', label='Password of account'), ) BROWSER = ChampslibresBrowser @@ -47,8 +47,6 @@ class ChampslibresBackend(BaseBackend, ICapBook): browser.login() return browser - - def get_rented(self): for book in self.browser.get_rented_books_list(): yield book @@ -57,8 +55,7 @@ class ChampslibresBackend(BaseBackend, ICapBook): raise NotImplementedError() def renew_book(self, id): - self.browser.renew(id) - + return self.browser.renew(id) def iter_books(self): #for book in self.get_booked(): diff --git a/modules/champslibres/browser.py b/modules/champslibres/browser.py index 49fa1806..030fa0cf 100644 --- a/modules/champslibres/browser.py +++ b/modules/champslibres/browser.py @@ -29,7 +29,7 @@ __all__ = ['ChampslibresBrowser'] # Browser class ChampslibresBrowser(BaseBrowser): PROTOCOL = 'http' - ENCODING = None + ENCODING = 'utf-8' PAGES = { '.*login.*': LoginPage, '.*home\?lang=frf.*': HomePage, @@ -66,6 +66,7 @@ class ChampslibresBrowser(BaseBrowser): self.location('https://sbib.si.leschampslibres.fr/patroninfo~S1*frf/%s/items' % self.iduser) self.page.renew(id) self.page.confirm_renew() + return self.page.read_renew(id) # TODO def get_booked_books_list(self): diff --git a/modules/champslibres/pages.py b/modules/champslibres/pages.py index aa4cd5ba..9488320b 100644 --- a/modules/champslibres/pages.py +++ b/modules/champslibres/pages.py @@ -18,9 +18,10 @@ # along with weboob. If not, see . from datetime import date -from weboob.capabilities.library import Book +from weboob.capabilities.library import Book, Renew from weboob.tools.browser import BasePage from weboob.tools.mech import ClientForm +from weboob.tools.misc import html2text class SkipPage(BasePage): @@ -62,11 +63,20 @@ class RentedPage(BasePage): self.browser.controls.append(ClientForm.TextControl('text', 'requestRenewSome', {'value': 'requestRenewSome'})) self.browser.submit() - def confirm_renew(self): + def confirm_renew(self): self.browser.select_form("checkout_form") self.browser.form.set_all_readonly(False) self.browser.submit(name='renewsome') + def read_renew(self, id): + for tr in self.document.getroot().xpath('//tr[@class="patFuncEntry"]'): + if len(tr.xpath('td/input[@value="%s"]' % id)) > 0: + message = self.browser.parser.tostring(tr.xpath('td[@class="patFuncStatus"]')[0]) + renew = Renew(id) + renew.message = html2text(message).replace('\n', '') + return renew + + class HistoryPage(BasePage): pass diff --git a/weboob/applications/boobooks/boobooks.py b/weboob/applications/boobooks/boobooks.py index b28e895c..07df1cf2 100644 --- a/weboob/applications/boobooks/boobooks.py +++ b/weboob/applications/boobooks/boobooks.py @@ -20,7 +20,7 @@ from weboob.capabilities.library import ICapBook, Book from weboob.tools.application.repl import ReplApplication from weboob.tools.application.formatters.iformatter import IFormatter - +import sys __all__ = ['Boobooks'] @@ -78,4 +78,6 @@ class Boobooks(ReplApplication): return 2 names = (backend_name,) if backend_name is not None else None - self.do('renew_book', id, backends=names) + for backend, renew in self.do('renew_book', id, backends=names): + self.format(renew) + self.flush() diff --git a/weboob/capabilities/library.py b/weboob/capabilities/library.py index 2f1b1ed7..594fbdef 100644 --- a/weboob/capabilities/library.py +++ b/weboob/capabilities/library.py @@ -35,6 +35,10 @@ class Book(CapBaseObject): self.add_field('date', (datetime, date)) # which may be the due date self.add_field('late', bool) +class Renew(CapBaseObject): + def __init__(self, id): + CapBaseObject.__init__(self, id) + self.add_field('message', basestring) class ICapBook(ICapCollection): def iter_resources(self, objs, split_path):