From 24ab55169489c5c027a8dfe9d5de8e037fb2b7f0 Mon Sep 17 00:00:00 2001 From: jems Date: Tue, 13 Mar 2012 19:49:55 +0100 Subject: [PATCH] add library capability and backend and application for archimede software aloes http://www.archimed.fr/aloes/presentation-et-avantages-12.html Signed-off-by: jems Signed-off-by: Romain Bignon --- modules/opacwebaloes/__init__.py | 23 +++++ modules/opacwebaloes/backend.py | 70 +++++++++++++++ modules/opacwebaloes/browser.py | 78 ++++++++++++++++ modules/opacwebaloes/favicon.png | Bin 0 -> 2547 bytes modules/opacwebaloes/pages.py | 110 +++++++++++++++++++++++ modules/opacwebaloes/test.py | 27 ++++++ scripts/boobooks | 27 ++++++ weboob/applications/boobooks/__init__.py | 23 +++++ weboob/applications/boobooks/boobooks.py | 66 ++++++++++++++ weboob/capabilities/library.py | 60 +++++++++++++ 10 files changed, 484 insertions(+) create mode 100644 modules/opacwebaloes/__init__.py create mode 100644 modules/opacwebaloes/backend.py create mode 100644 modules/opacwebaloes/browser.py create mode 100644 modules/opacwebaloes/favicon.png create mode 100644 modules/opacwebaloes/pages.py create mode 100644 modules/opacwebaloes/test.py create mode 100755 scripts/boobooks create mode 100644 weboob/applications/boobooks/__init__.py create mode 100644 weboob/applications/boobooks/boobooks.py create mode 100644 weboob/capabilities/library.py diff --git a/modules/opacwebaloes/__init__.py b/modules/opacwebaloes/__init__.py new file mode 100644 index 00000000..bb0ece21 --- /dev/null +++ b/modules/opacwebaloes/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2011 Jeremy Monnet +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + + +from .backend import AloesBackend + +__all__ = ['AloesBackend'] diff --git a/modules/opacwebaloes/backend.py b/modules/opacwebaloes/backend.py new file mode 100644 index 00000000..ace4b50f --- /dev/null +++ b/modules/opacwebaloes/backend.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2012 Jeremy Monnet +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + + +from __future__ import with_statement + +from weboob.capabilities.library import ICapBook +from weboob.tools.backend import BaseBackend, BackendConfig +from weboob.tools.value import ValueBackendPassword, Value + +from .browser import AloesBrowser + + +__all__ = ['AloesBackend'] + + +class AloesBackend(BaseBackend, ICapBook): + NAME = 'opacwebaloes' + MAINTAINER = u'Jeremy Monnet' + EMAIL = 'jmonnet@gmail.com' + VERSION = '0.b' + DESCRIPTION = 'Aloes Library software' + LICENSE = 'AGPLv3+' + CONFIG = BackendConfig(Value('login', label='Account ID', regexp='^\d{1,6}\w$'), + ValueBackendPassword('password', label='Password of account'), + Value('baseurl', label='Base URL') + ) + BROWSER = AloesBrowser + + def create_default_browser(self): + return self.create_browser(self.config['baseurl'].get(), + self.config['login'].get(), + self.config['password'].get()) + + def get_rented(self): + for book in self.browser.get_rented_books_list(): + yield book + + def get_booked(self): + for book in self.browser.get_booked_books_list(): + yield book + + def iter_books(self): + for book in self.get_booked(): + yield book + for book in self.get_rented(): + yield book + + def get_book(self, _id): + raise NotImplementedError() + + def search_books(self, _string): + raise NotImplementedError() + diff --git a/modules/opacwebaloes/browser.py b/modules/opacwebaloes/browser.py new file mode 100644 index 00000000..07df74cf --- /dev/null +++ b/modules/opacwebaloes/browser.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2012 Jeremy Monnet +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + + +from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword + +from .pages import LoginPage, HomePage, RentedPage, HistoryPage, BookedPage + + +__all__ = ['AloesBrowser'] + + +# Browser +class AloesBrowser(BaseBrowser): + PROTOCOL = 'http' + ENCODING = 'utf-8' + USER_AGENT = BaseBrowser.USER_AGENTS['desktop_firefox'] + #DEBUG_HTTP = True + DEBUG_HTTP = False + PAGES = { + 'http://.*/index.aspx': LoginPage, + 'http://.*/index.aspx\?IdPage=1': HomePage, + 'http://.*/index.aspx\?IdPage=45': RentedPage, + 'http://.*/index.aspx\?IdPage=429': HistoryPage, + 'http://.*/index.aspx\?IdPage=44': BookedPage + } + + def __init__(self, baseurl, *args, **kwargs): + self.BASEURL=baseurl + BaseBrowser.__init__(self, *args, **kwargs) + + def is_logged(self): + + return self.page \ + and not self.page.document.getroot().xpath('//input[contains(@id, "ctl00_ContentPlaceHolder1_ctl00_ctl08_ctl00_TextSaisie")]') + #return True + + def login(self): + assert isinstance(self.username, basestring) + assert isinstance(self.password, basestring) + if not self.is_on_page(HomePage): + self.location('%s://%s/index.aspx' \ + % (self.PROTOCOL, self.BASEURL), + no_login=True) + if not self.page.login(self.username, self.password) or \ + not self.is_logged() or \ + (self.is_on_page(LoginPage) and self.page.is_error()) : + raise BrowserIncorrectPassword() + + + def get_rented_books_list(self): + if not self.is_on_page(RentedPage): + self.location('%s://%s/index.aspx?IdPage=45' \ + % (self.PROTOCOL, self.BASEURL) + ) + return self.page.get_list() + + def get_booked_books_list(self): + if not self.is_on_page(BookedPage): + self.location('%s://%s/index.aspx?IdPage=44' \ + % (self.PROTOCOL, self.BASEURL)) + return self.page.get_list() diff --git a/modules/opacwebaloes/favicon.png b/modules/opacwebaloes/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..beb49765fedb9f26637f9ee95ec30d7b77b1fdc5 GIT binary patch literal 2547 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 JPDHLkV1hia&DQ_` literal 0 HcmV?d00001 diff --git a/modules/opacwebaloes/pages.py b/modules/opacwebaloes/pages.py new file mode 100644 index 00000000..640d1b9d --- /dev/null +++ b/modules/opacwebaloes/pages.py @@ -0,0 +1,110 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2012 Jeremy Monnet +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + +from datetime import date +from weboob.capabilities.library import Book +from weboob.tools.browser import BasePage, BrowserUnavailable +from weboob.tools.mech import ClientForm + +class SkipPage(BasePage): + pass + +class HomePage(BasePage): + pass + +def txt2date(s): + return date(*reversed([int(x) for x in s.split(' ')[-1].split('/')])) + + +class RentedPage(BasePage): + # TODO, table limited to 20 items, need to use pagination + def get_list(self): + for book in self.iter_books('//tr[contains(@id, "ctl00_ContentPlaceHolder1_ctl00_ctl07_COMPTE_PRET_1_1_GrillePrets_ctl00__")]', 1): + book.late = False + yield book + + for book in self.iter_books('//tr[contains(@id, "ctl00_ContentPlaceHolder1_ctl00_ctl08_COMPTE_RETARD_0_1_GrilleRetards_ctl00__")]', 0): + book.late = True + yield book + + def iter_books(self, el, start): + for tr in self.document.getroot().xpath(el): + book = Book(tr[start].text) + book.name = tr[start+3].text + book.author = tr[start+4].text + book.date = txt2date(tr[start+5].text) + yield book + +class HistoryPage(BasePage): + pass + + +class BookedPage(BasePage): + # TODO, table limited to 20 items, need to use pagination + def get_list(self): + for tr in self.document.getroot().xpath('//tr[contains(@id, "ctl00_ContentPlaceHolder1_ctl00_ctl09_COMPTE_INFOS_0_GrilleInfos_ctl00__0")]'): + username=tr[1].text+"_"+tr[0].text + + for i, tr in enumerate(self.document.getroot().xpath('//tr[contains(@id, "ctl00_ContentPlaceHolder1_ctl00_ctl10_COMPTE_RESA_1_1_GrilleResas_ctl00__")]')): + book = Book('%s%d' % (username, i)) + # if all the books booked are available, there are only 7 columns. + # if (at least ?) one book is still not available, yous can cancel, and the first column does contain the checkbox. So 8 columns. + if (len(tr) == 7): + start = 2 + if (len(tr) == 8): + start = 3 + book.name = tr[start].text + book.author = tr[start+1].text + book.date = txt2date(tr[start+3].text) + book.late = False + yield book + +class LoginPage(BasePage): + def login(self, login, passwd): + self.browser.select_form(predicate=lambda x: x.attrs.get('id','')=='aspnetForm') + self.browser.form.set_all_readonly(False) + self.browser['ctl00$ContentPlaceHolder1$ctl00$ctl04$ctl00$TextSaisie'] = login + self.browser['ctl00$ContentPlaceHolder1$ctl00$ctl04$ctl00$TextPass'] = passwd + self.browser['ctl00_ScriptManager1_TSM']="%3B%3BSystem.Web.Extensions%2C%20Version%3D1.0.61025.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D31bf3856ad364e35%3Afr-FR%3A1f0f78f9-0731-4ae9-b308-56936732ccb8%3Aea597d4b%3Ab25378d2%3BTelerik.Web.UI%2C%20Version%3D2009.3.1314.20%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D121fae78165ba3d4%3Afr-FR%3Aec1048f9-7413-49ac-913a-b3b534cde186%3A16e4e7cd%3Aed16cbdc%3Af7645509%3A24ee1bba%3A19620875%3A874f8ea2%3A33108d14%3Abd8f85e4" + self.browser.controls.append(ClientForm.TextControl('text', 'RadAJAXControlID', {'value': ''})) + self.browser['RadAJAXControlID']="ctl00_ContentPlaceHolder1_ctl00_ctl04_ctl00_RadAjaxPanelConnexion" + self.browser.controls.append(ClientForm.TextControl('text', 'ctl00$ScriptManager1', {'value': ''})) + self.browser['ctl00$ScriptManager1']="ctl00$ContentPlaceHolder1$ctl00$ctl04$ctl00$ctl00$ContentPlaceHolder1$ctl00$ctl04$ctl00$RadAjaxPanelConnexionPanel|" + self.browser.controls.append(ClientForm.TextControl('text', '__EVENTTARGET', {'value': ''})) + self.browser.controls.append(ClientForm.TextControl('text', '__EVENTARGUMENT', {'value': ''})) + self.browser.controls.append(ClientForm.TextControl('text', 'ctl00$ContentPlaceHolder1$ctl00$ctl04$ctl00$btnImgConnexion.x', {'value': ''})) + self.browser['ctl00$ContentPlaceHolder1$ctl00$ctl04$ctl00$btnImgConnexion.x']="76" + self.browser.controls.append(ClientForm.TextControl('text', 'ctl00$ContentPlaceHolder1$ctl00$ctl04$ctl00$btnImgConnexion.y', {'value': ''})) + self.browser['ctl00$ContentPlaceHolder1$ctl00$ctl04$ctl00$btnImgConnexion.y']="10" + + try: + self.browser.submit() + except BrowserUnavailable: + # Login is not valid + return False + return True + + def is_error(self): + for text in self.document.find('body').itertext(): + text=text.strip() + # Login seems valid, but password does not + needle='Echec lors de l\'authentification' + if text.startswith(needle.decode('utf-8')): + return True + return False diff --git a/modules/opacwebaloes/test.py b/modules/opacwebaloes/test.py new file mode 100644 index 00000000..d105c76d --- /dev/null +++ b/modules/opacwebaloes/test.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2011 Jeremy Monnet +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + + +from weboob.tools.test import BackendTest + +class AloestTest(BackendTest): + BACKEND = 'aloes' + + def test_aloes(self): + pass diff --git a/scripts/boobooks b/scripts/boobooks new file mode 100755 index 00000000..9b988b3e --- /dev/null +++ b/scripts/boobooks @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai + +# Copyright(C) 2012 Jeremy Monnet +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + + +from weboob.applications.boobooks import Boobooks + + +if __name__ == '__main__': + Boobooks.run() diff --git a/weboob/applications/boobooks/__init__.py b/weboob/applications/boobooks/__init__.py new file mode 100644 index 00000000..84ce3274 --- /dev/null +++ b/weboob/applications/boobooks/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2011 Jérémy Monnet +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + + +from .boobooks import Boobooks + +__all__ = ['Boobooks'] diff --git a/weboob/applications/boobooks/boobooks.py b/weboob/applications/boobooks/boobooks.py new file mode 100644 index 00000000..79433f02 --- /dev/null +++ b/weboob/applications/boobooks/boobooks.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2009-2012 Jeremy Monnet +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + +from weboob.capabilities.library import ICapBook, Book +from weboob.tools.application.repl import ReplApplication +from weboob.tools.application.formatters.iformatter import IFormatter + + +__all__ = ['Boobooks'] + + +class RentedListFormatter(IFormatter): + MANDATORY_FIELDS = ('id', 'date', 'author', 'name', 'late') + + RED = '' + + count = 0 + + def flush(self): + self.count = 0 + + def format_dict(self, item): + self.count += 1 + + if self.interactive: + backend = item['id'].split('@', 1)[1] + id = '#%d (%s)' % (self.count, backend) + else: + id = item['id'] + + s = u'%s%s%s %s — %s (%s)' % (self.BOLD, id, self.NC, item['author'], item['name'], item['date']) + if item['late']: + s += u' %sLATE!%s' % (self.RED, self.NC) + return s + +class Boobooks(ReplApplication): + APPNAME = 'boobooks' + VERSION = '0.b' + COPYRIGHT = 'Copyright(C) 2012 Jeremy Monnet' + CAPS = ICapBook + DESCRIPTION = "Console application allowing to list your books rented or booked at the library, " \ + "book and search new ones, get your booking history (if available)." + EXTRA_FORMATTERS = {'rented_list': RentedListFormatter, + } + DEFAULT_FORMATTER = 'table' + COMMANDS_FORMATTERS = {'ls': 'rented_list', + 'list': 'rented_list', + } + + COLLECTION_OBJECTS = (Book, ) diff --git a/weboob/capabilities/library.py b/weboob/capabilities/library.py new file mode 100644 index 00000000..a15983b7 --- /dev/null +++ b/weboob/capabilities/library.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2012 Jeremy Monnet +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + +from datetime import datetime, date + +from .collection import ICapCollection, CollectionNotFound +from .base import CapBaseObject + + +__all__ = ['ICapBook', 'Book'] + + +class Book(CapBaseObject): + def __init__(self, id): + CapBaseObject.__init__(self, id) + self.add_field('name', basestring) + self.add_field('author', basestring) + self.add_field('location', basestring) + self.add_field('date', (datetime, date)) # which may be the due date + self.add_field('late', bool) + + +class ICapBook(ICapCollection): + def iter_resources(self, objs, split_path): + if Book in objs: + if len(split_path) > 0: + raise CollectionNotFound(split_path) + + return self.iter_books() + + def iter_books(self, pattern): + raise NotImplementedError() + + def get_book(self, _id): + raise NotImplementedError() + + def get_booked(self, _id): + raise NotImplementedError() + + def get_rented(self, _id): + raise NotImplementedError() + + def search_books(self, _string): + raise NotImplementedError()