add module alloresto
This commit is contained in:
parent
7b6c5e8544
commit
ec10ec3382
6 changed files with 280 additions and 0 deletions
23
modules/alloresto/__init__.py
Normal file
23
modules/alloresto/__init__.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2014 Romain Bignon
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from .backend import AlloRestoBackend
|
||||
|
||||
__all__ = ['AlloRestoBackend']
|
||||
68
modules/alloresto/backend.py
Normal file
68
modules/alloresto/backend.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2014 Romain Bignon
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
from weboob.capabilities.bank import ICapBank, AccountNotFound
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.value import ValueBackendPassword
|
||||
|
||||
from .browser import AlloRestoBrowser
|
||||
|
||||
|
||||
__all__ = ['AlloRestoBackend']
|
||||
|
||||
|
||||
class AlloRestoBackend(BaseBackend, ICapBank):
|
||||
NAME = 'alloresto'
|
||||
MAINTAINER = u'Romain Bignon'
|
||||
EMAIL = 'romain@weboob.org'
|
||||
VERSION = '0.i'
|
||||
DESCRIPTION = u'Allo Resto'
|
||||
LICENSE = 'AGPLv3+'
|
||||
CONFIG = BackendConfig(ValueBackendPassword('login', label='Identifiant', masked=False),
|
||||
ValueBackendPassword('password', label='Mot de passe'))
|
||||
BROWSER = AlloRestoBrowser
|
||||
|
||||
def create_default_browser(self):
|
||||
return self.create_browser(self.config['login'].get(),
|
||||
self.config['password'].get())
|
||||
|
||||
def iter_accounts(self):
|
||||
with self.browser:
|
||||
for account in self.browser.get_accounts_list():
|
||||
yield account
|
||||
|
||||
def get_account(self, _id):
|
||||
with self.browser:
|
||||
account = self.browser.get_account(_id)
|
||||
|
||||
if account:
|
||||
return account
|
||||
else:
|
||||
raise AccountNotFound()
|
||||
|
||||
def iter_history(self, account):
|
||||
with self.browser:
|
||||
return self.browser.get_history(account)
|
||||
|
||||
def iter_coming(self, account):
|
||||
with self.browser:
|
||||
return self.browser.get_coming(account)
|
||||
|
||||
83
modules/alloresto/browser.py
Normal file
83
modules/alloresto/browser.py
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2014 Romain Bignon
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||
|
||||
from .pages import LoginPage, AccountsPage
|
||||
|
||||
|
||||
__all__ = ['AlloRestoBrowser']
|
||||
|
||||
|
||||
class AlloRestoBrowser(BaseBrowser):
|
||||
DOMAIN = 'www.alloresto.fr'
|
||||
PROTOCOL = 'http'
|
||||
ENCODING = 'utf-8'
|
||||
PAGES = {'http://www.alloresto.fr/identification-requise.*': LoginPage,
|
||||
'http://www.alloresto.fr/chez-moi/releve-compte-miams': AccountsPage,
|
||||
}
|
||||
|
||||
def is_logged(self):
|
||||
return self.page is not None and not self.is_on_page(LoginPage)
|
||||
|
||||
def home(self):
|
||||
self.go_on_accounts_list()
|
||||
|
||||
def login(self):
|
||||
assert isinstance(self.username, basestring)
|
||||
assert isinstance(self.password, basestring)
|
||||
|
||||
if not self.is_on_page(LoginPage):
|
||||
self.location('http://www.alloresto.fr/identification-requise', no_login=True)
|
||||
|
||||
self.page.login(self.username, self.password)
|
||||
|
||||
if not self.is_logged():
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
def go_on_accounts_list(self):
|
||||
self.location('http://www.alloresto.fr/chez-moi/releve-compte-miams')
|
||||
|
||||
def get_accounts_list(self):
|
||||
if not self.is_on_page(AccountsPage):
|
||||
self.go_on_accounts_list()
|
||||
return self.page.get_list()
|
||||
|
||||
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(AccountsPage):
|
||||
self.go_on_accounts_list()
|
||||
|
||||
return self.page.get_transactions()
|
||||
|
||||
def get_coming(self, account):
|
||||
if not self.is_on_page(AccountsPage):
|
||||
self.go_on_accounts_list()
|
||||
|
||||
return self.page.get_transactions('acquisition')
|
||||
BIN
modules/alloresto/favicon.png
Normal file
BIN
modules/alloresto/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
74
modules/alloresto/pages.py
Normal file
74
modules/alloresto/pages.py
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2014 Romain Bignon
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from weboob.tools.browser import BasePage, BrokenPageError
|
||||
from weboob.capabilities.bank import Account
|
||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction as Transaction
|
||||
|
||||
|
||||
__all__ = ['LoginPage', 'AccountsPage']
|
||||
|
||||
|
||||
class LoginPage(BasePage):
|
||||
def login(self, username, password):
|
||||
self.browser.select_form(nr=0)
|
||||
self.browser['uname'] = username.encode(self.browser.ENCODING)
|
||||
self.browser['pass'] = password.encode(self.browser.ENCODING)
|
||||
self.browser.submit(nologin=True)
|
||||
|
||||
|
||||
class AccountsPage(BasePage):
|
||||
def get_list(self):
|
||||
a = Account()
|
||||
a.id = '0'
|
||||
a.label = u'Compte miams'
|
||||
a.balance = Decimal(self.parser.tocleanstring(self.document.xpath('//div[@class="compteur"]//strong')[0]))
|
||||
a.currency = u'MIAM'
|
||||
try:
|
||||
a.coming = Decimal(Transaction.clean_amount(self.document.xpath('//table[@id="solde_acquisition_lignes"]//th[@class="col_montant"]')[0].text))
|
||||
except BrokenPageError:
|
||||
a.coming = Decimal('0')
|
||||
yield a
|
||||
|
||||
COL_DATE = 0
|
||||
COL_LABEL = 1
|
||||
COL_AMOUNT = 2
|
||||
|
||||
MONTHS = ['janv', u'févr', u'mars', u'avr', u'mai', u'juin', u'juil', u'août', u'sept', u'oct', u'nov', u'déc']
|
||||
def get_transactions(self, _type='consommable'):
|
||||
for tr in self.document.xpath('//table[@id="solde_%s_lignes"]/tbody/tr' % _type):
|
||||
cols = tr.findall('td')
|
||||
|
||||
t = Transaction(0)
|
||||
|
||||
day, month, year = self.parser.tocleanstring(cols[self.COL_DATE]).split(' ')
|
||||
day = int(day)
|
||||
year = int(year)
|
||||
month = self.MONTHS.index(month.rstrip('.')) + 1
|
||||
date = datetime.date(year, month, day)
|
||||
|
||||
label = self.parser.tocleanstring(cols[self.COL_LABEL])
|
||||
t.parse(date, label)
|
||||
t.set_amount(self.parser.tocleanstring(cols[self.COL_AMOUNT]))
|
||||
|
||||
yield t
|
||||
32
modules/alloresto/test.py
Normal file
32
modules/alloresto/test.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2014 Romain Bignon
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.tools.test import BackendTest
|
||||
|
||||
|
||||
class AlloRestoTest(BackendTest):
|
||||
BACKEND = 'alloresto'
|
||||
|
||||
def test_alloresto(self):
|
||||
l = list(self.backend.iter_accounts())
|
||||
|
||||
a = l[0]
|
||||
list(self.backend.iter_history(a))
|
||||
list(self.backend.iter_coming(a))
|
||||
Loading…
Add table
Add a link
Reference in a new issue