Display renew confirmation/errors
This commit is contained in:
parent
03f998a33f
commit
65251c4ceb
5 changed files with 24 additions and 10 deletions
|
|
@ -35,7 +35,7 @@ class ChampslibresBackend(BaseBackend, ICapBook):
|
||||||
VERSION = '0.c'
|
VERSION = '0.c'
|
||||||
DESCRIPTION = 'Champs Libres (Rennes) Library'
|
DESCRIPTION = 'Champs Libres (Rennes) Library'
|
||||||
LICENSE = 'AGPLv3+'
|
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'),
|
ValueBackendPassword('password', label='Password of account'),
|
||||||
)
|
)
|
||||||
BROWSER = ChampslibresBrowser
|
BROWSER = ChampslibresBrowser
|
||||||
|
|
@ -47,8 +47,6 @@ class ChampslibresBackend(BaseBackend, ICapBook):
|
||||||
browser.login()
|
browser.login()
|
||||||
return browser
|
return browser
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_rented(self):
|
def get_rented(self):
|
||||||
for book in self.browser.get_rented_books_list():
|
for book in self.browser.get_rented_books_list():
|
||||||
yield book
|
yield book
|
||||||
|
|
@ -57,8 +55,7 @@ class ChampslibresBackend(BaseBackend, ICapBook):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def renew_book(self, id):
|
def renew_book(self, id):
|
||||||
self.browser.renew(id)
|
return self.browser.renew(id)
|
||||||
|
|
||||||
|
|
||||||
def iter_books(self):
|
def iter_books(self):
|
||||||
#for book in self.get_booked():
|
#for book in self.get_booked():
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ __all__ = ['ChampslibresBrowser']
|
||||||
# Browser
|
# Browser
|
||||||
class ChampslibresBrowser(BaseBrowser):
|
class ChampslibresBrowser(BaseBrowser):
|
||||||
PROTOCOL = 'http'
|
PROTOCOL = 'http'
|
||||||
ENCODING = None
|
ENCODING = 'utf-8'
|
||||||
PAGES = {
|
PAGES = {
|
||||||
'.*login.*': LoginPage,
|
'.*login.*': LoginPage,
|
||||||
'.*home\?lang=frf.*': HomePage,
|
'.*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.location('https://sbib.si.leschampslibres.fr/patroninfo~S1*frf/%s/items' % self.iduser)
|
||||||
self.page.renew(id)
|
self.page.renew(id)
|
||||||
self.page.confirm_renew()
|
self.page.confirm_renew()
|
||||||
|
return self.page.read_renew(id)
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
def get_booked_books_list(self):
|
def get_booked_books_list(self):
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,10 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from datetime import date
|
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.browser import BasePage
|
||||||
from weboob.tools.mech import ClientForm
|
from weboob.tools.mech import ClientForm
|
||||||
|
from weboob.tools.misc import html2text
|
||||||
|
|
||||||
|
|
||||||
class SkipPage(BasePage):
|
class SkipPage(BasePage):
|
||||||
|
|
@ -62,11 +63,20 @@ class RentedPage(BasePage):
|
||||||
self.browser.controls.append(ClientForm.TextControl('text', 'requestRenewSome', {'value': 'requestRenewSome'}))
|
self.browser.controls.append(ClientForm.TextControl('text', 'requestRenewSome', {'value': 'requestRenewSome'}))
|
||||||
self.browser.submit()
|
self.browser.submit()
|
||||||
|
|
||||||
def confirm_renew(self):
|
def confirm_renew(self):
|
||||||
self.browser.select_form("checkout_form")
|
self.browser.select_form("checkout_form")
|
||||||
self.browser.form.set_all_readonly(False)
|
self.browser.form.set_all_readonly(False)
|
||||||
self.browser.submit(name='renewsome')
|
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):
|
class HistoryPage(BasePage):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
from weboob.capabilities.library import ICapBook, Book
|
from weboob.capabilities.library import ICapBook, Book
|
||||||
from weboob.tools.application.repl import ReplApplication
|
from weboob.tools.application.repl import ReplApplication
|
||||||
from weboob.tools.application.formatters.iformatter import IFormatter
|
from weboob.tools.application.formatters.iformatter import IFormatter
|
||||||
|
import sys
|
||||||
|
|
||||||
__all__ = ['Boobooks']
|
__all__ = ['Boobooks']
|
||||||
|
|
||||||
|
|
@ -78,4 +78,6 @@ class Boobooks(ReplApplication):
|
||||||
return 2
|
return 2
|
||||||
names = (backend_name,) if backend_name is not None else None
|
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()
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,10 @@ class Book(CapBaseObject):
|
||||||
self.add_field('date', (datetime, date)) # which may be the due date
|
self.add_field('date', (datetime, date)) # which may be the due date
|
||||||
self.add_field('late', bool)
|
self.add_field('late', bool)
|
||||||
|
|
||||||
|
class Renew(CapBaseObject):
|
||||||
|
def __init__(self, id):
|
||||||
|
CapBaseObject.__init__(self, id)
|
||||||
|
self.add_field('message', basestring)
|
||||||
|
|
||||||
class ICapBook(ICapCollection):
|
class ICapBook(ICapCollection):
|
||||||
def iter_resources(self, objs, split_path):
|
def iter_resources(self, objs, split_path):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue