Commit 952a100a authored by Laurent Bachelier's avatar Laurent Bachelier 🐧 Committed by ntome

amazonstorecard: flake8 fixes, Python 3

parent 3b1637d1
......@@ -18,18 +18,17 @@
# 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
from weboob.tools.compat import unquote
import json
import os
from subprocess import STDOUT, CalledProcessError, check_output
from tempfile import mkstemp
from subprocess import check_output, STDOUT, CalledProcessError
from .pages import SomePage, StatementsPage, StatementPage, SummaryPage, \
ActivityPage
from weboob.browser import URL, LoginBrowser, need_login
from weboob.capabilities.bank import AccountNotFound
from weboob.exceptions import BrowserIncorrectPassword
from weboob.tools.compat import unquote
from .pages import ActivityPage, SomePage, StatementPage, StatementsPage, SummaryPage
__all__ = ['AmazonStoreCard']
......@@ -66,24 +65,24 @@ class AmazonStoreCard(LoginBrowser):
'agent': self.session.headers['User-Agent']})
os.close(scrf)
os.close(cookf)
for i in xrange(self.MAX_RETRIES):
for i in range(self.MAX_RETRIES):
try:
check_output(["phantomjs", scrn], stderr=STDOUT)
break
except CalledProcessError as error:
pass
last_error = error
else:
raise error
raise last_error
with open(cookn) as cookf:
cookies = json.loads(cookf.read())
os.remove(scrn)
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)
if not self.summary.go().logged:
raise BrowserIncorrectPassword()
......@@ -106,6 +105,7 @@ class AmazonStoreCard(LoginBrowser):
for t in s.iter_transactions():
yield t
LOGIN_JS = u'''\
var TIMEOUT = %(timeout)s*1000; // milliseconds
var page = require('webpage').create();
......
......@@ -19,12 +19,11 @@
from weboob.capabilities.bank import CapBank
from weboob.tools.backend import Module, BackendConfig
from weboob.tools.backend import BackendConfig, Module
from weboob.tools.value import ValueBackendPassword
from .browser import AmazonStoreCard
__all__ = ['AmazonStoreCardModule']
......@@ -39,16 +38,16 @@ class AmazonStoreCardModule(Module, CapBank):
ValueBackendPassword('username', label='User ID', masked=False),
ValueBackendPassword('password', label='Password'),
ValueBackendPassword('phone',
label='Phone to send verification code to', masked=False),
label='Phone to send verification code to', masked=False),
ValueBackendPassword('code_file',
label='File to read the verification code from', masked=False))
label='File to read the verification code from', masked=False))
BROWSER = AmazonStoreCard
def create_default_browser(self):
return self.create_browser(username = self.config['username'].get(),
password = self.config['password'].get(),
phone = self.config['phone'].get(),
code_file = self.config['code_file'].get())
return self.create_browser(username=self.config['username'].get(),
password=self.config['password'].get(),
phone=self.config['phone'].get(),
code_file=self.config['code_file'].get())
def iter_accounts(self):
return self.browser.iter_accounts()
......
......@@ -26,10 +26,18 @@ from weboob.tools.date import closest_date
from weboob.tools.pdf import decompress_pdf
from weboob.tools.tokenizer import ReTokenizer
from datetime import datetime, timedelta
from weboob.tools.compat import unicode
import re
import json
try:
cmp = cmp
except NameError:
def cmp(x, y):
return (x > y) - (x < y)
class SomePage(HTMLPage):
@property
def logged(self):
......@@ -39,7 +47,7 @@ class SomePage(HTMLPage):
class SummaryPage(SomePage):
def account(self):
label = u' '.join(self.doc.xpath(
'//div[contains(@class,"myCreditCardDetails")]')[0]\
'//div[contains(@class,"myCreditCardDetails")]')[0]
.text_content().split())
balance = self.amount(u'Balance')
cardlimit = self.doc.xpath(
......@@ -69,8 +77,8 @@ class SummaryPage(SomePage):
def amount(self, name):
return u''.join(self.doc.xpath(
u'//li[text()[.="%s"]]/../li[1]'%name)[0].text_content().split())\
.replace(u'\xb7',u'.').replace(u'*',u'')
u'//li[text()[.="%s"]]/../li[1]' % name)[0].text_content().split())\
.replace(u'\xb7', u'.').replace(u'*', u'')
class ActivityPage(SomePage):
......@@ -98,19 +106,20 @@ class ActivityPage(SomePage):
def parse_date(recdate):
return datetime.strptime(recdate, u'%B %d, %Y')
class StatementsPage(SomePage):
def iter_statements(self):
jss = self.doc.xpath(u'//a/@onclick[contains(.,"eBillViewPDFAction")]')
for js in jss:
url = re.match("window.open\('([^']*).*\)", js).group(1)
for i in xrange(self.browser.MAX_RETRIES):
for i in range(self.browser.MAX_RETRIES):
try:
self.browser.location(url)
break
except ServerError as e:
pass
last_error = e
else:
raise e
raise last_error
yield self.browser.page
......@@ -163,7 +172,7 @@ class StatementPage(RawPage):
pos, amount_layout = self.read_layout_td(pos)
pos, amount = self.read_amount(pos)
if tdate is None or pdate is None \
or desc is None or amount is None or amount == 0:
or desc is None or amount is None or amount == 0:
return startPos, None
else:
tdate = closest_date(tdate, date_from, date_to)
......@@ -208,7 +217,7 @@ class StatementPage(RawPage):
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