Commit af2303dc authored by Laurent Bachelier's avatar Laurent Bachelier 🐧 Committed by ntome

wellsfargo: flake8 fixes, Python 3

parent 3ad6b9ad
......@@ -18,23 +18,20 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.bank import AccountNotFound
from weboob.browser import LoginBrowser, URL, need_login
from weboob.exceptions import BrowserIncorrectPassword, BrowserUnavailable
from weboob.tools.compat import unquote
import ssl
import json
import os
from tempfile import mkstemp
import ssl
from subprocess import STDOUT, CalledProcessError, check_output
from tempfile import mkstemp
from .pages import LoginProceedPage, LoginRedirectPage, \
SummaryPage, ActivityCashPage, ActivityCardPage, \
DocumentsPage, StatementPage, StatementsPage, \
StatementsEmbeddedPage, LoggedInPage, CodeRequestPage, \
CodeSubmitPage
from weboob.browser import URL, LoginBrowser, need_login
from weboob.capabilities.bank import AccountNotFound
from weboob.exceptions import BrowserIncorrectPassword, BrowserUnavailable
from weboob.tools.compat import unquote
from .pages import (ActivityCardPage, ActivityCashPage, CodeRequestPage, CodeSubmitPage, DocumentsPage, LoggedInPage,
LoginProceedPage, LoginRedirectPage, StatementPage, StatementsEmbeddedPage, StatementsPage,
SummaryPage)
__all__ = ['WellsFargo']
......@@ -63,14 +60,14 @@ class WellsFargo(LoginBrowser):
documents = URL('https://connect.secure.wellsfargo.com'
'/accounts/start\?.+$', DocumentsPage)
statements_embedded = URL('https://connect.secure.wellsfargo.com'
'/accounts/start\?.+$', StatementsEmbeddedPage)
'/accounts/start\?.+$', StatementsEmbeddedPage)
statements = URL('https://connect.secure.wellsfargo.com'
'/accounts/documents/statement/list.+$',
StatementsPage)
statement = URL('https://connect.secure.wellsfargo.com'
'/accounts/documents/retrieve/.+$',
StatementPage)
unknown = URL('/.*$', LoggedInPage) # E.g. random advertisement pages.
unknown = URL('/.*$', LoggedInPage) # e.g. random advertisement pages.
def __init__(self, question1, answer1, question2, answer2,
question3, answer3, phone_last4, code_file, *args, **kwargs):
......@@ -90,7 +87,7 @@ class WellsFargo(LoginBrowser):
which uses DOM. For now the easiest option seems to be to run it in
PhantomJs.
'''
for i in xrange(self.MAX_RETRIES):
for i in range(self.MAX_RETRIES):
scrf, scrn = mkstemp('.js')
cookf, cookn = mkstemp('.json')
os.write(scrf, LOGIN_JS % {
......@@ -118,10 +115,10 @@ class WellsFargo(LoginBrowser):
os.remove(cookn)
self.session.cookies.clear()
for c in cookies:
for k in ['expiry', 'expires', 'httponly']:
c.pop(k, None)
c['value'] = unquote(c['value'])
self.session.cookies.set(**c)
for k in ['expiry', 'expires', 'httponly']:
c.pop(k, None)
c['value'] = unquote(c['value'])
self.session.cookies.set(**c)
self.summary.go()
if self.page.logged:
break
......@@ -190,7 +187,7 @@ class WellsFargo(LoginBrowser):
@need_login
def to_statements(self, id_=None, year=None):
if not self.statements.is_here() \
and not self.statements_embedded.is_here():
and not self.statements_embedded.is_here():
self.to_summary()
self.page.to_documents()
if self.documents.is_here():
......@@ -209,7 +206,7 @@ class WellsFargo(LoginBrowser):
@need_login
def to_statement(self, uri):
for i in xrange(self.MAX_RETRIES):
for i in range(self.MAX_RETRIES):
self.location(uri)
if self.statement.is_here():
break
......@@ -242,6 +239,7 @@ class WellsFargo(LoginBrowser):
for trans in self.page.iter_transactions():
yield trans
LOGIN_JS = u'''\
var page = require('webpage').create();
......
......@@ -17,20 +17,29 @@
# 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 Account, Transaction
from weboob.tools.capabilities.bank.transactions import \
AmericanTransaction as AmTr
from weboob.browser.pages import HTMLPage, LoggedPage, RawPage
from decimal import Decimal
from requests.cookies import morsel_to_cookie
from .parsers import StatementParser, clean_label
from time import sleep
import Cookie
import datetime
import itertools
import json
import re
import os
import datetime
import Cookie
import re
from decimal import Decimal
from time import sleep
from requests.cookies import morsel_to_cookie
from weboob.browser.pages import HTMLPage, LoggedPage, RawPage
from weboob.capabilities.bank import Account, Transaction
from weboob.tools.capabilities.bank.transactions import AmericanTransaction as AmTr
from .parsers import StatementParser, clean_label
try:
cmp = cmp
except NameError:
def cmp(x, y):
return (x > y) - (x < y)
class LoginProceedPage(LoggedPage, HTMLPage):
......@@ -98,7 +107,7 @@ class CodeSubmitPage(LoggedInPage):
except IOError:
sleep(1)
os.remove(self.browser.code_file)
self.browser.logger.info('The code %s has been successfully read'%code)
self.browser.logger.info('The code %s has been successfully read' % code)
form = self.get_form(name='otp')
form['passcode'] = [code]
del form['cancelBtn']
......@@ -122,7 +131,7 @@ class SummaryPage(LoggedInPage):
class AccountPage(object):
def account_id(self, name=None):
if name:
return name[-4:] # Last 4 digits of "BLAH XXXXXXX1234"
return name[-4:] # Last 4 digits of "BLAH XXXXXXX1234"
else:
return self.account_id(self.account_name())
......@@ -391,7 +400,7 @@ class StatementsEmbeddedPage(LoggedInPage):
def get_embedded_data(self):
scr = self.doc.xpath(self.SCRIPT_XPATH)[0]
data = json.loads('\n'.join(scr.split('\n')[2:-2]).replace(
"'appendTo'",'"appendTo"'))
"'appendTo'", '"appendTo"'))
return json.loads(data['data'])
def parser(self):
......@@ -401,8 +410,8 @@ class StatementsEmbeddedPage(LoggedInPage):
class WfJsonPage(LoggedPage, RawPage):
def __init__(self, *args, **kwArgs):
RawPage.__init__(self, *args, **kwArgs)
clean = self.doc.replace('"/*WellFargoProprietary%','') \
.replace('%WellFargoProprietary*/"','').decode('string_escape')
clean = self.doc.replace('"/*WellFargoProprietary%', '') \
.replace('%WellFargoProprietary*/"', '').decode('string_escape')
self.doc = json.loads(clean)
......
......@@ -23,6 +23,7 @@ from weboob.tools.capabilities.bank.transactions import \
from weboob.tools.date import closest_date
from weboob.tools.pdf import decompress_pdf
from weboob.tools.tokenizer import ReTokenizer
from weboob.tools.compat import unicode
import re
import datetime
......@@ -124,7 +125,7 @@ class StatementParser(object):
range_plus = (0, INDENT_CHARGES))
if tdate is None or pdate_layout is None or pdate is None \
or ref_layout is None or ref is None or desc is None or amount is None:
or ref_layout is None or ref is None or desc is None or amount is None:
return startPos, None
else:
tdate = closest_date(tdate, date_from, date_to)
......@@ -262,19 +263,19 @@ class StatementParser(object):
def read_date(self, pos):
def parse_date(v):
for year in [1900, 1904]: # try leap and non-leap years
for year in [1900, 1904]: # try leap and non-leap years
fullstr = '%s/%i' % (v, year)
try:
return datetime.datetime.strptime(fullstr, '%m/%d/%Y')
except ValueError as e:
pass
raise e
last_error = e
raise last_error
return self._tok.simple_read('date', pos, parse_date)
def read_text(self, pos):
t = self._tok.tok(pos)
#TODO: handle PDF encodings properly.
# TODO: handle PDF encodings properly.
return (pos+1, unicode(t.value(), errors='ignore')) \
if t.is_text() else (pos, None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment