Improved Wells Fargo module stability.
Signed-off-by: Oleg Plakhotniuk <olegus8@gmail.com>
This commit is contained in:
parent
b1f20b5489
commit
cbd084283d
3 changed files with 109 additions and 119 deletions
|
|
@ -24,8 +24,9 @@ from weboob.capabilities.bank import AccountNotFound
|
|||
from weboob.browser import LoginBrowser, URL, need_login
|
||||
from weboob.exceptions import BrowserIncorrectPassword
|
||||
|
||||
from .pages import LoginPage, LoginRedirectPage, LoggedInPage, SummaryPage, \
|
||||
DynamicPage
|
||||
from .pages import LoginPage, LoginProceedPage, LoginRedirectPage, \
|
||||
SummaryPage, ActivityCashPage, ActivityCardPage, \
|
||||
StatementsPage, StatementPage, LoggedInPage
|
||||
|
||||
|
||||
__all__ = ['WellsFargo']
|
||||
|
|
@ -34,45 +35,58 @@ __all__ = ['WellsFargo']
|
|||
class WellsFargo(LoginBrowser):
|
||||
BASEURL = 'https://online.wellsfargo.com'
|
||||
login = URL('/$', LoginPage)
|
||||
loginRedirect = URL('/das/cgi-bin/session.cgi\?screenid=SIGNON$',
|
||||
LoginRedirectPage)
|
||||
loggedIn = URL('/das/cgi-bin/session.cgi\?screenid=SIGNON_PORTAL_PAUSE$',
|
||||
'/das/cgi-bin/session.cgi\?screenid=SIGNON&LOB=CONS$',
|
||||
'/login\?ERROR_CODE=.*LOB=CONS&$',
|
||||
LoggedInPage)
|
||||
login_proceed = URL('/das/cgi-bin/session.cgi\?screenid=SIGNON.*$',
|
||||
'/login\?ERROR_CODE=.*LOB=CONS&$',
|
||||
LoginProceedPage)
|
||||
login_redirect = URL('/das/cgi-bin/session.cgi\?screenid=SIGNON.*$',
|
||||
'/login\?ERROR_CODE=.*LOB=CONS&$',
|
||||
LoginRedirectPage)
|
||||
summary = URL('/das/channel/accountSummary$', SummaryPage)
|
||||
dynamic = URL('/das/cgi-bin/session.cgi\?sessargs=.+$',
|
||||
'/das/channel/accountActivityDDA\?action=doSetPage&page=.*$',
|
||||
DynamicPage)
|
||||
|
||||
_pause = 1
|
||||
activity_cash = URL('/das/cgi-bin/session.cgi\?sessargs=.+$',
|
||||
ActivityCashPage)
|
||||
activity_card = URL('/das/cgi-bin/session.cgi\?sessargs=.+$',
|
||||
ActivityCardPage)
|
||||
statements = URL(
|
||||
'/das/cgi-bin/session.cgi\?sessargs=.+$',
|
||||
'/das/channel/accountActivityDDA\?action=doSetPage&page=.*$',
|
||||
StatementsPage)
|
||||
statement = URL('/das/cgi-bin/session.cgi\?sessargs=.+$',
|
||||
StatementPage)
|
||||
unknown = URL('/.*$', LoggedInPage) # E.g. random advertisement pages.
|
||||
|
||||
def do_login(self):
|
||||
self.session.cookies.clear()
|
||||
self.login.go()
|
||||
self.page.login(self.username, self.password)
|
||||
if not self.loginRedirect.is_here():
|
||||
if not self.page.logged:
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
# Sometimes Wells Fargo server returns "Session time out" error
|
||||
# right after login if we don't make a pause here.
|
||||
sleep(self._pause)
|
||||
self._pause = min(30, self._pause*2)
|
||||
self.page.redirect()
|
||||
self._pause = 1
|
||||
def location(self, *args, **kwargs):
|
||||
"""
|
||||
Wells Fargo inserts redirecting pages from time to time,
|
||||
so we should follow them whenever we see them.
|
||||
"""
|
||||
r = super(WellsFargo, self).location(*args, **kwargs)
|
||||
if self.login_proceed.is_here():
|
||||
return self.page.proceed()
|
||||
elif self.login_redirect.is_here():
|
||||
return self.page.redirect()
|
||||
else:
|
||||
return r
|
||||
|
||||
def get_account(self, id_):
|
||||
self.to_activity()
|
||||
if id_ not in self.page.subpage.accounts_ids():
|
||||
if id_ not in self.page.accounts_ids():
|
||||
raise AccountNotFound()
|
||||
else:
|
||||
self.to_activity(id_)
|
||||
return self.page.subpage.get_account()
|
||||
return self.page.get_account()
|
||||
|
||||
def get_accounts(self):
|
||||
def iter_accounts(self):
|
||||
self.to_activity()
|
||||
for id_ in self.page.subpage.accounts_ids():
|
||||
for id_ in self.page.accounts_ids():
|
||||
self.to_activity(id_)
|
||||
yield self.page.subpage.get_account()
|
||||
yield self.page.get_account()
|
||||
|
||||
@need_login
|
||||
def to_summary(self):
|
||||
|
|
@ -80,10 +94,7 @@ class WellsFargo(LoginBrowser):
|
|||
assert self.summary.is_here()
|
||||
|
||||
def is_activity(self):
|
||||
try:
|
||||
return self.page.subpage.is_activity()
|
||||
except AttributeError:
|
||||
return False
|
||||
return self.activity_cash.is_here() or self.activity_card.is_here()
|
||||
|
||||
@need_login
|
||||
def to_activity(self, id_=None):
|
||||
|
|
@ -91,42 +102,30 @@ class WellsFargo(LoginBrowser):
|
|||
self.to_summary()
|
||||
self.page.to_activity()
|
||||
assert self.is_activity()
|
||||
if id_ and self.page.subpage.account_id() != id_:
|
||||
self.page.subpage.to_account(id_)
|
||||
if id_ and self.page.account_id() != id_:
|
||||
self.page.to_account(id_)
|
||||
assert self.is_activity()
|
||||
assert self.page.subpage.account_id() == id_
|
||||
|
||||
def is_statements(self):
|
||||
try:
|
||||
return self.page.subpage.is_statements()
|
||||
except AttributeError:
|
||||
return False
|
||||
assert self.page.account_id() == id_
|
||||
|
||||
@need_login
|
||||
def to_statements(self, id_=None, year=None):
|
||||
if not self.is_statements():
|
||||
if not self.statements.is_here():
|
||||
self.to_summary()
|
||||
self.page.to_statements()
|
||||
assert self.is_statements()
|
||||
if id_ and self.page.subpage.account_id() != id_:
|
||||
self.page.subpage.to_account(id_)
|
||||
assert self.is_statements()
|
||||
assert self.page.subpage.account_id() == id_
|
||||
if year and self.page.subpage.year() != year:
|
||||
self.page.subpage.to_year(year)
|
||||
assert self.is_statements()
|
||||
assert self.page.subpage.year() == year
|
||||
|
||||
def is_statement(self):
|
||||
try:
|
||||
return self.page.subpage.is_statement()
|
||||
except AttributeError:
|
||||
return False
|
||||
assert self.statements.is_here()
|
||||
if id_ and self.page.account_id() != id_:
|
||||
self.page.to_account(id_)
|
||||
assert self.statements.is_here()
|
||||
assert self.page.account_id() == id_
|
||||
if year and self.page.year() != year:
|
||||
self.page.to_year(year)
|
||||
assert self.statements.is_here()
|
||||
assert self.page.year() == year
|
||||
|
||||
@need_login
|
||||
def to_statement(self, uri):
|
||||
self.location(uri)
|
||||
assert self.is_statement()
|
||||
assert self.statement.is_here()
|
||||
|
||||
def iter_history(self, account):
|
||||
self.to_activity(account.id)
|
||||
|
|
@ -138,19 +137,18 @@ class WellsFargo(LoginBrowser):
|
|||
# transactions grouped by statement period will not be available
|
||||
# for up to seven days."
|
||||
# (www.wellsfargo.com, 2014-07-20)
|
||||
if self.page.subpage.since_last_statement():
|
||||
assert self.page.subpage.account_id() == account.id
|
||||
if self.page.since_last_statement():
|
||||
assert self.page.account_id() == account.id
|
||||
while True:
|
||||
for trans in self.page.subpage.iter_transactions():
|
||||
for trans in self.page.iter_transactions():
|
||||
yield trans
|
||||
if not self.page.subpage.next_():
|
||||
if not self.page.next_():
|
||||
break
|
||||
|
||||
self.to_statements(account.id)
|
||||
for year in self.page.subpage.years():
|
||||
for year in self.page.years():
|
||||
self.to_statements(account.id, year)
|
||||
for stmt in self.page.subpage.statements():
|
||||
for stmt in self.page.statements():
|
||||
self.to_statement(stmt)
|
||||
for trans in self.page.subpage.iter_transactions():
|
||||
for trans in self.page.iter_transactions():
|
||||
yield trans
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue