remove lot of fucking shit and keep card transactions in separate card accounts
This commit is contained in:
parent
9e61376aa6
commit
78f6127f9e
3 changed files with 14 additions and 73 deletions
|
|
@ -98,8 +98,8 @@ class BredBrowser(Browser):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def iter_transactions(self, id, is_coming=None):
|
def get_history(self, account):
|
||||||
numero_compte, numero_poste = id.split('.')
|
numero_compte, numero_poste = account.id.split('.')
|
||||||
data = {'typeDemande': 'recherche',
|
data = {'typeDemande': 'recherche',
|
||||||
'motRecherche': '',
|
'motRecherche': '',
|
||||||
'numero_compte': numero_compte,
|
'numero_compte': numero_compte,
|
||||||
|
|
@ -113,16 +113,4 @@ class BredBrowser(Browser):
|
||||||
self.location('https://www.%s.fr/Andromede/Ecriture' % self.website, urllib.urlencode(data))
|
self.location('https://www.%s.fr/Andromede/Ecriture' % self.website, urllib.urlencode(data))
|
||||||
|
|
||||||
assert self.is_on_page(TransactionsPage)
|
assert self.is_on_page(TransactionsPage)
|
||||||
return self.page.get_history(is_coming)
|
return self.page.get_history()
|
||||||
|
|
||||||
def get_history(self, account):
|
|
||||||
for tr in self.iter_transactions(account.id):
|
|
||||||
yield tr
|
|
||||||
|
|
||||||
for tr in self.get_card_operations(account):
|
|
||||||
yield tr
|
|
||||||
|
|
||||||
def get_card_operations(self, account):
|
|
||||||
for id in account._card_links:
|
|
||||||
for tr in self.iter_transactions(id, True):
|
|
||||||
yield tr
|
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,4 @@ class BredModule(Module, CapBank):
|
||||||
|
|
||||||
def iter_history(self, account):
|
def iter_history(self, account):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
transactions = list(self.browser.get_history(account))
|
return self.browser.get_history(account)
|
||||||
transactions.sort(key=lambda tr: tr.rdate, reverse=True)
|
|
||||||
return [tr for tr in transactions if not tr._is_coming]
|
|
||||||
|
|
||||||
def iter_coming(self, account):
|
|
||||||
with self.browser:
|
|
||||||
transactions = list(self.browser.get_card_operations(account))
|
|
||||||
transactions.sort(key=lambda tr: tr.rdate, reverse=True)
|
|
||||||
return [tr for tr in transactions if tr._is_coming]
|
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,6 @@ class BredBasePage(Page):
|
||||||
|
|
||||||
class AccountsPage(BredBasePage):
|
class AccountsPage(BredBasePage):
|
||||||
def get_list(self):
|
def get_list(self):
|
||||||
accounts = []
|
|
||||||
|
|
||||||
for tr in self.document.xpath('//table[@class="compteTable"]/tr'):
|
for tr in self.document.xpath('//table[@class="compteTable"]/tr'):
|
||||||
if not tr.attrib.get('class', '').startswith('ligne_'):
|
if not tr.attrib.get('class', '').startswith('ligne_'):
|
||||||
continue
|
continue
|
||||||
|
|
@ -153,21 +151,19 @@ class AccountsPage(BredBasePage):
|
||||||
|
|
||||||
a = cols[0].find('a')
|
a = cols[0].find('a')
|
||||||
if a is None:
|
if a is None:
|
||||||
# this line is a cards line. attach it on the first account.
|
|
||||||
if len(accounts) == 0:
|
|
||||||
self.logger.warning('There is a card link but no accounts!')
|
|
||||||
continue
|
|
||||||
|
|
||||||
for a in cols[0].xpath('.//li/a'):
|
for a in cols[0].xpath('.//li/a'):
|
||||||
args = self.js2args(a.attrib['href'])
|
args = self.js2args(a.attrib['href'])
|
||||||
if not 'numero_compte' in args or not 'numero_poste' in args:
|
if not 'numero_compte' in args or not 'numero_poste' in args:
|
||||||
self.logger.warning('Card link with strange args: %s' % args)
|
self.logger.warning('Card link with strange args: %s' % args)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
accounts[0]._card_links.append('%s.%s' % (args['numero_compte'], args['numero_poste']))
|
account = Account()
|
||||||
if not accounts[0].coming:
|
account.id = '%s.%s' % (args['numero_compte'], args['numero_poste'])
|
||||||
accounts[0].coming = Decimal('0.0')
|
account.label = u'Carte %s' % self.parser.tocleanstring(a)
|
||||||
accounts[0].coming += amount
|
account.balance = amount
|
||||||
|
account.type = account.TYPE_CARD
|
||||||
|
account.currency = [account.get_currency(txt) for txt in cols[-1].itertext() if len(txt.strip()) > 0][0]
|
||||||
|
yield account
|
||||||
continue
|
continue
|
||||||
|
|
||||||
args = self.js2args(a.attrib['href'])
|
args = self.js2args(a.attrib['href'])
|
||||||
|
|
@ -181,10 +177,7 @@ class AccountsPage(BredBasePage):
|
||||||
account.label = to_unicode(a.attrib.get('alt', a.text.strip()))
|
account.label = to_unicode(a.attrib.get('alt', a.text.strip()))
|
||||||
account.balance = amount
|
account.balance = amount
|
||||||
account.currency = [account.get_currency(txt) for txt in cols[-1].itertext() if len(txt.strip()) > 0][0]
|
account.currency = [account.get_currency(txt) for txt in cols[-1].itertext() if len(txt.strip()) > 0][0]
|
||||||
account._card_links = []
|
yield account
|
||||||
accounts.append(account)
|
|
||||||
|
|
||||||
return accounts
|
|
||||||
|
|
||||||
|
|
||||||
class Transaction(FrenchTransaction):
|
class Transaction(FrenchTransaction):
|
||||||
|
|
@ -208,14 +201,7 @@ class Transaction(FrenchTransaction):
|
||||||
|
|
||||||
|
|
||||||
class TransactionsPage(Page):
|
class TransactionsPage(Page):
|
||||||
def get_history(self, is_coming=None):
|
def get_history(self):
|
||||||
last_debit = None
|
|
||||||
transactions = []
|
|
||||||
|
|
||||||
# check if it's a card page, so by default transactions are not yet debited.
|
|
||||||
if len(self.document.xpath('//div[@class="scrollTbody"]/table//th')) == 6 and is_coming is None:
|
|
||||||
is_coming = True
|
|
||||||
|
|
||||||
for tr in self.document.xpath('//div[@class="scrollTbody"]/table//tr'):
|
for tr in self.document.xpath('//div[@class="scrollTbody"]/table//tr'):
|
||||||
cols = tr.findall('td')
|
cols = tr.findall('td')
|
||||||
|
|
||||||
|
|
@ -229,12 +215,6 @@ class TransactionsPage(Page):
|
||||||
date = self.parser.tocleanstring(cols[0])
|
date = self.parser.tocleanstring(cols[0])
|
||||||
label = self.parser.tocleanstring(col_label)
|
label = self.parser.tocleanstring(col_label)
|
||||||
|
|
||||||
# always strip card debits transactions. if we are on a card page, all next
|
|
||||||
# transactions will be probably already debited.
|
|
||||||
if label.startswith('DEBIT MENSUEL '):
|
|
||||||
is_coming = False
|
|
||||||
continue
|
|
||||||
|
|
||||||
t = Transaction(col_label.attrib.get('id', ''))
|
t = Transaction(col_label.attrib.get('id', ''))
|
||||||
|
|
||||||
# an optional tooltip on page contain the second part of the transaction label.
|
# an optional tooltip on page contain the second part of the transaction label.
|
||||||
|
|
@ -256,23 +236,4 @@ class TransactionsPage(Page):
|
||||||
credit = self.parser.tocleanstring(cols[-1])
|
credit = self.parser.tocleanstring(cols[-1])
|
||||||
t.set_amount(credit, debit)
|
t.set_amount(credit, debit)
|
||||||
|
|
||||||
if 'CUMUL DES DEPENSES CARTES BANCAIRES REGLEES' in t.raw:
|
yield t
|
||||||
if last_debit is None:
|
|
||||||
last_debit = t.date
|
|
||||||
continue
|
|
||||||
|
|
||||||
t._is_coming = bool(is_coming)
|
|
||||||
|
|
||||||
# If this is a card, get the right debit date (rdate is already set
|
|
||||||
# with the operation date with t.parse())
|
|
||||||
if is_coming is not None:
|
|
||||||
t.date = t.parse_date(self.parser.tocleanstring(cols[-3]))
|
|
||||||
|
|
||||||
transactions.append(t)
|
|
||||||
|
|
||||||
if last_debit is not None and is_coming is True:
|
|
||||||
for tr in transactions:
|
|
||||||
if tr.date <= last_debit.replace(day=1):
|
|
||||||
tr._is_coming = False
|
|
||||||
|
|
||||||
return iter(transactions)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue