[weboob] [PATCH 1/1] add library capability and backend for archimede software aloes http://www.archimed.fr/aloes/presentation-et-avantages-12.html

Romain Bignon romain at symlink.me
Sat Mar 3 22:39:02 CET 2012


Hi,

On 02/Mar - 10:51, jems wrote:
> ---
>  modules/opacwebaloes/__init__.py |   23 +++++
>  modules/opacwebaloes/backend.py  |   69 +++++++++++++++
>  modules/opacwebaloes/browser.py  |   97 ++++++++++++++++++++
>  modules/opacwebaloes/favicon.png |  Bin 0 -> 2401 bytes
>  modules/opacwebaloes/pages.py    |  179 ++++++++++++++++++++++++++++++++++++++
>  modules/opacwebaloes/test.py     |   27 ++++++
>  weboob/capabilities/library.py   |   56 ++++++++++++
>  7 files changed, 451 insertions(+), 0 deletions(-)
>  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 100644 weboob/capabilities/library.py

Thanks for your patch. I think we have to review together it to validate the
capability API.

Also, I'll merge it only when the corresponding application will be available.

Here are a few remarks about your patch:

> --- /dev/null
> +++ b/weboob/capabilities/backend.py

> +    VERSION = '0.a'

Should be 0.b here.

> +    DESCRIPTION = 'Aloes Library software'
> +    LICENSE = 'AGPLv3+'
> +    CONFIG = BackendConfig(ValueBackendPassword('login',    label='Account ID', regexp='^\d{1,6}\w$', masked=False),
> +                           ValueBackendPassword('password', label='Password of account')
> +                           )

If your module is related to a web application, perhaps you should add an URL
parameter. Or, if you want to support only cataloguebm.villeurbanne.fr, rename
the module.

> +    def iter_books(self):
> +      self.browser.login()
> +      for book in self.get_booked():
> +        yield book
> +      for book in self.get_rented():
> +        yield book

Indentation problems here, please be sure you use 4 spaces for each indent
level.

> --- /dev/null
> +++ b/weboob/capabilities/browser.py

> +    USER_AGENT = BaseBrowser.USER_AGENTS['wget']

Why?

> +    def __init__(self, *args, **kwargs):
> +        BaseBrowser.__init__(self, *args, **kwargs)

You can remove it as it does nothing.

> +    def is_logged(self):
> +        #return self.page and not self.is_on_page(HomePage)
> +        return True

It's important to know if you are logged or no, to re-login when a session
expires or something like that.

> +    def get_rented_books_list(self):
> +       if not self.is_on_page(RentedPage):
> +	   self.location('%s://%s/opacwebaloes/index.aspx?IdPage=45' \
> +                      % (self.PROTOCOL, self.DOMAIN),
> +                      no_login=True)
> +       return self.page.get_list()

Indentation problems here too, please avoid to use tabs.

> +    #def get_account(self, id):
> +    #    assert isinstance(id, basestring)
> +
> +    #    l = self.get_accounts_list()
> +    #    for a in l:
> +    #        if a.id == id:
> +    #            return a
> +
> +    #    return None
> +
> +    #def get_history(self,account):
> +    #    if not self.is_on_page(AccountHistoryPage) :
> +    #        self.location('%s://%s%s' % (self.PROTOCOL, self.DOMAIN, account.link_id))
> +    #    return self.page.get_operations(account)
> +
> +    #def get_coming_operations(self, account):
> +    #    if not self.is_on_page(AccountComing) or self.page.account.id != account.id:
> +    #        self.location('/NS_AVEEC?ch4=%s' % account.link_id)
> +    #    return self.page.get_operations()

To remove.

> diff --git a/modules/opacwebaloes/favicon.png b/modules/opacwebaloes/favicon.png
> new file mode 100644

Unfortunately, this is the LCL module icon. Please, try to draw a beautiful one
for your module :).

> --- /dev/null
> +++ b/weboob/capabilities/pages.py

> +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"

I want to exterminate the guys who have written this web application.

> --- /dev/null
> +++ b/weboob/capabilities/test.py

> +    def test_aloes(self):
> +        #list(self.backend.iter_accounts())

Add something like 'pass', because a method with only a comment produces a
syntax error.

Also, it's important to have right tests, to validate non-regressions and to
detect when the website has changed.

> --- /dev/null
> +++ b/weboob/capabilities/library.py

> +class Book(CapBaseObject):
> +    def __init__(self, id, name=NotLoaded, author=NotLoaded, pages=NotLoaded, url=NotLoaded, date=NotLoaded, location=NotLoaded, late=NotLoaded):

It's a deprecated way to give attributes in constructor. We should remove this
behaviour from ICapVideo and ICapTorrent capabilities.

> +        #self.add_field('pages', (int,long,float), size)

What's that?

> +        #self.add_field('date', datetime, date) # which may be the due date
> +        self.add_field('date', basestring, date) # which may be the due date

It should really be better to force datetime objects.

Finally, you should use tools/pyflakes.sh frequently, because there are a lot of
unused imports.

Romain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <https://lists.symlink.me/pipermail/weboob/attachments/20120303/55a06289/attachment.sig>


More information about the weboob mailing list