rewrite ganassurance with browser2 and fix auth and history
This commit is contained in:
parent
b9d3e87fda
commit
2446a7815c
3 changed files with 44 additions and 78 deletions
|
|
@ -18,7 +18,8 @@
|
|||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.deprecated.browser import Browser, BrowserIncorrectPassword
|
||||
from weboob.browser import LoginBrowser, URL, need_login
|
||||
from weboob.exceptions import BrowserIncorrectPassword
|
||||
|
||||
from .pages import LoginPage, AccountsPage, TransactionsPage
|
||||
|
||||
|
|
@ -26,24 +27,16 @@ from .pages import LoginPage, AccountsPage, TransactionsPage
|
|||
__all__ = ['GanAssurances']
|
||||
|
||||
|
||||
class GanAssurances(Browser):
|
||||
PROTOCOL = 'https'
|
||||
PAGES = {'https://[^/]+/wps/portal/login.*': LoginPage,
|
||||
'https://[^/]+/wps/myportal/TableauDeBord': AccountsPage,
|
||||
'https://[^/]+/wps/myportal/!ut.*': TransactionsPage,
|
||||
}
|
||||
class GanAssurances(LoginBrowser):
|
||||
login = URL('/wps/portal/login.*', LoginPage)
|
||||
accounts = URL('/wps/myportal/TableauDeBord', AccountsPage)
|
||||
transactions = URL('/wps/myportal/!ut.*', TransactionsPage)
|
||||
|
||||
def __init__(self, website, *args, **kwargs):
|
||||
self.DOMAIN = website
|
||||
Browser.__init__(self, *args, **kwargs)
|
||||
self.BASEURL = 'https://%s' % website
|
||||
super(GanAssurances, self).__init__(*args, **kwargs)
|
||||
|
||||
def is_logged(self):
|
||||
return self.page is not None and not self.is_on_page(LoginPage)
|
||||
|
||||
def home(self):
|
||||
self.location('/wps/myportal/TableauDeBord')
|
||||
|
||||
def login(self):
|
||||
def do_login(self):
|
||||
"""
|
||||
Attempt to log in.
|
||||
Note: this method does nothing if we are already logged in.
|
||||
|
|
@ -51,38 +44,25 @@ class GanAssurances(Browser):
|
|||
assert isinstance(self.username, basestring)
|
||||
assert isinstance(self.password, basestring)
|
||||
|
||||
if self.is_logged():
|
||||
return
|
||||
|
||||
if not self.is_on_page(LoginPage):
|
||||
self.home()
|
||||
self.login.stay_or_go()
|
||||
|
||||
self.page.login(self.username, self.password)
|
||||
|
||||
if not self.is_logged():
|
||||
if self.login.is_here():
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
@need_login
|
||||
def get_accounts_list(self):
|
||||
if not self.is_on_page(AccountsPage):
|
||||
self.location('/wps/myportal/TableauDeBord')
|
||||
self.accounts.stay_or_go()
|
||||
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 account._link is None:
|
||||
return iter([])
|
||||
|
||||
self.location(account._link)
|
||||
assert self.is_on_page(TransactionsPage)
|
||||
|
||||
assert self.transactions.is_here()
|
||||
|
||||
return self.page.get_history()
|
||||
|
||||
|
|
@ -91,9 +71,9 @@ class GanAssurances(Browser):
|
|||
return iter([])
|
||||
|
||||
self.location(account._link)
|
||||
assert self.is_on_page(TransactionsPage)
|
||||
assert self.transactions.is_here()
|
||||
|
||||
self.location(self.page.get_coming_link())
|
||||
assert self.is_on_page(TransactionsPage)
|
||||
assert self.transactions.is_here()
|
||||
|
||||
return self.page.get_history()
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
|
||||
from weboob.capabilities.bank import CapBank, AccountNotFound
|
||||
from weboob.capabilities.base import find_object
|
||||
from weboob.tools.backend import Module, BackendConfig
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
from weboob.tools.value import ValueBackendPassword, Value
|
||||
|
|
@ -51,22 +52,13 @@ class GanAssurancesModule(Module, CapBank):
|
|||
self.config['password'].get())
|
||||
|
||||
def iter_accounts(self):
|
||||
with self.browser:
|
||||
return self.browser.get_accounts_list()
|
||||
return self.browser.get_accounts_list()
|
||||
|
||||
def get_account(self, _id):
|
||||
with self.browser:
|
||||
account = self.browser.get_account(_id)
|
||||
|
||||
if account:
|
||||
return account
|
||||
else:
|
||||
raise AccountNotFound()
|
||||
return find_object(self.browser.get_accounts_list(), id=_id, error=AccountNotFound)
|
||||
|
||||
def iter_history(self, account):
|
||||
with self.browser:
|
||||
return self.browser.get_history(account)
|
||||
return self.browser.get_history(account)
|
||||
|
||||
def iter_coming(self, account):
|
||||
with self.browser:
|
||||
return self.browser.get_coming(account)
|
||||
return self.browser.get_coming(account)
|
||||
|
|
|
|||
|
|
@ -21,21 +21,22 @@
|
|||
from decimal import Decimal
|
||||
import re
|
||||
|
||||
from weboob.deprecated.browser import Page
|
||||
from weboob.browser.pages import HTMLPage
|
||||
from weboob.browser.elements import method
|
||||
from weboob.capabilities.bank import Account
|
||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||
|
||||
|
||||
class LoginPage(Page):
|
||||
class LoginPage(HTMLPage):
|
||||
def login(self, login, passwd):
|
||||
self.browser.select_form(name='loginForm')
|
||||
self.browser.set_all_readonly(False)
|
||||
self.browser['LoginPortletFormID'] = login.encode(self.browser.ENCODING)
|
||||
self.browser['LoginPortletFormPassword1'] = passwd.encode(self.browser.ENCODING)
|
||||
self.browser.submit(nologin=True)
|
||||
form = self.get_form(name='loginForm')
|
||||
form['LoginPortletFormID'] = login
|
||||
form['LoginPortletFormPassword1'] = passwd
|
||||
form.submit()
|
||||
|
||||
|
||||
class AccountsPage(Page):
|
||||
class AccountsPage(HTMLPage):
|
||||
logged = True
|
||||
ACCOUNT_TYPES = {u'Solde des comptes bancaires - Groupama Banque': Account.TYPE_CHECKING,
|
||||
u'Epargne bancaire constituée - Groupama Banque': Account.TYPE_SAVINGS,
|
||||
}
|
||||
|
|
@ -44,7 +45,7 @@ class AccountsPage(Page):
|
|||
account_type = Account.TYPE_UNKNOWN
|
||||
accounts = []
|
||||
|
||||
for tr in self.document.xpath('//table[@class="ecli"]/tr'):
|
||||
for tr in self.doc.xpath('//table[@class="ecli"]/tr'):
|
||||
if tr.attrib.get('class', '') == 'entete':
|
||||
account_type = self.ACCOUNT_TYPES.get(tr.find('th').text.strip(), Account.TYPE_UNKNOWN)
|
||||
continue
|
||||
|
|
@ -88,28 +89,21 @@ class Transaction(FrenchTransaction):
|
|||
]
|
||||
|
||||
|
||||
class TransactionsPage(Page):
|
||||
def get_history(self):
|
||||
count = 0
|
||||
for tr in self.document.xpath('//table[@id="releve_operation"]/tr'):
|
||||
tds = tr.findall('td')
|
||||
class TransactionsPage(HTMLPage):
|
||||
logged = True
|
||||
|
||||
if len(tds) < 4:
|
||||
continue
|
||||
@method
|
||||
class get_history(Transaction.TransactionsElement):
|
||||
head_xpath = '//table[@id="releve_operation"]//tr/th'
|
||||
item_xpath = '//table[@id="releve_operation"]//tr'
|
||||
|
||||
t = Transaction(count)
|
||||
col_date = [u'Date opé']
|
||||
col_vdate = [u'Date valeur']
|
||||
|
||||
date = u''.join([txt.strip() for txt in tds[0].itertext()])
|
||||
raw = u' '.join([txt.strip() for txt in tds[1].itertext()])
|
||||
debit = u''.join([txt.strip() for txt in tds[-2].itertext()])
|
||||
credit = u''.join([txt.strip() for txt in tds[-1].itertext()])
|
||||
t.parse(date, re.sub(r'[ ]+', ' ', raw))
|
||||
t.set_amount(credit, debit)
|
||||
|
||||
yield t
|
||||
|
||||
count += 1
|
||||
class item(Transaction.TransactionElement):
|
||||
def condition(self):
|
||||
return len(self.el.xpath('./td')) > 3
|
||||
|
||||
def get_coming_link(self):
|
||||
a = self.document.getroot().cssselect('div#sous_nav ul li a.bt_sans_off')[0]
|
||||
a = self.doc.getroot().cssselect('div#sous_nav ul li a.bt_sans_off')[0]
|
||||
return re.sub('[ \t\r\n]+', '', a.attrib['href'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue