use FrenchTransaction and detect type of transactions
This commit is contained in:
parent
bad531679a
commit
3d6b792c34
1 changed files with 45 additions and 13 deletions
|
|
@ -17,20 +17,24 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import re
|
||||||
import base64
|
import base64
|
||||||
from datetime import date
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from weboob.capabilities.bank import Transaction
|
|
||||||
from weboob.capabilities.bank import Account
|
|
||||||
from weboob.tools.browser import BasePage, BrowserUnavailable
|
|
||||||
from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError
|
|
||||||
from logging import error
|
from logging import error
|
||||||
import tempfile
|
import tempfile
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
from weboob.capabilities.bank import Account
|
||||||
|
from weboob.tools.browser import BasePage, BrowserUnavailable
|
||||||
|
from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError
|
||||||
|
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['SkipPage', 'LoginPage', 'AccountsPage', 'AccountHistoryPage']
|
||||||
|
|
||||||
|
|
||||||
class LCLVirtKeyboard(MappedVirtKeyboard):
|
class LCLVirtKeyboard(MappedVirtKeyboard):
|
||||||
symbols={'0': '9da2724133f2221482013151735f033c',
|
symbols={'0': '9da2724133f2221482013151735f033c',
|
||||||
'1': '873ab0087447610841ae1332221be37b',
|
'1': '873ab0087447610841ae1332221be37b',
|
||||||
|
|
@ -155,10 +159,31 @@ class AccountsPage(BasePage):
|
||||||
if '-' in balance:
|
if '-' in balance:
|
||||||
balance='-'+balance.replace('-', '')
|
balance='-'+balance.replace('-', '')
|
||||||
account.balance=Decimal(balance)
|
account.balance=Decimal(balance)
|
||||||
|
self.logger.debug('%s Type: %s' % (account.label, account._type))
|
||||||
l.append(account)
|
l.append(account)
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
|
||||||
|
class Transaction(FrenchTransaction):
|
||||||
|
PATTERNS = [(re.compile('^(?P<category>CB) (?P<text>RETRAIT) DU (?P<dd>\d+)/(?P<mm>\d+)'),
|
||||||
|
FrenchTransaction.TYPE_WITHDRAWAL),
|
||||||
|
(re.compile('^(?P<category>PRLV) (?P<text>.*)'),
|
||||||
|
FrenchTransaction.TYPE_ORDER),
|
||||||
|
(re.compile('^(?P<category>CHQ\.) (?P<text>.*)'),
|
||||||
|
FrenchTransaction.TYPE_CHECK),
|
||||||
|
(re.compile('^(?P<category>RELEVE CB) AU (?P<dd>\d+)/(?P<mm>\d+)/(?P<yy>\d+)'),
|
||||||
|
FrenchTransaction.TYPE_CARD),
|
||||||
|
(re.compile('^(?P<category>(PRELEVEMENT|TELEREGLEMENT|TIP)) (?P<text>.*)'),
|
||||||
|
FrenchTransaction.TYPE_ORDER),
|
||||||
|
(re.compile('^(?P<category>ECHEANCEPRET)(?P<text>.*)'), FrenchTransaction.TYPE_LOAN_PAYMENT),
|
||||||
|
(re.compile('^(?P<category>VIR(EMEN)?T? ((RECU|FAVEUR) TIERS|SEPA RECU)?)( /FRM)?(?P<text>.*)'),
|
||||||
|
FrenchTransaction.TYPE_TRANSFER),
|
||||||
|
(re.compile('^(?P<category>REMBOURST)(?P<text>.*)'), FrenchTransaction.TYPE_PAYBACK),
|
||||||
|
(re.compile('^(?P<category>COMMISSIONS)(?P<text>.*)'), FrenchTransaction.TYPE_BANK),
|
||||||
|
(re.compile('^(?P<text>(?P<category>REMUNERATION).*)'), FrenchTransaction.TYPE_BANK),
|
||||||
|
(re.compile('^(?P<category>REM CHQ) (?P<text>.*)'), FrenchTransaction.TYPE_DEPOSIT),
|
||||||
|
]
|
||||||
|
|
||||||
class AccountHistoryPage(BasePage):
|
class AccountHistoryPage(BasePage):
|
||||||
def get_operations(self,account):
|
def get_operations(self,account):
|
||||||
operations = []
|
operations = []
|
||||||
|
|
@ -188,26 +213,33 @@ class AccountHistoryPage(BasePage):
|
||||||
if len(tr.findall("th"))!=0 or\
|
if len(tr.findall("th"))!=0 or\
|
||||||
len(tr.findall("td"))<=1:
|
len(tr.findall("td"))<=1:
|
||||||
continue
|
continue
|
||||||
operation=Transaction(len(operations))
|
|
||||||
mntColumn=0
|
mntColumn=0
|
||||||
|
|
||||||
|
date = None
|
||||||
|
raw = None
|
||||||
|
credit = ''
|
||||||
|
debit = ''
|
||||||
for td in tr.iter('td'):
|
for td in tr.iter('td'):
|
||||||
value=td.attrib.get('id')
|
value=td.attrib.get('id')
|
||||||
if value is None:
|
if value is None:
|
||||||
value=td.attrib.get('class');
|
value=td.attrib.get('class');
|
||||||
if value.startswith("date"):
|
if value.startswith("date"):
|
||||||
# some transaction are included in a <strong> tag
|
# some transaction are included in a <strong> tag
|
||||||
value=u''.join([txt.strip() for txt in td.itertext()])
|
date=u''.join([txt.strip() for txt in td.itertext()])
|
||||||
operation.date=date(*reversed([int(x) for x in value.split('/')]))
|
|
||||||
elif value.startswith("lib") or value.startswith("opLib"):
|
elif value.startswith("lib") or value.startswith("opLib"):
|
||||||
# misclosed A tag requires to grab text from td
|
# misclosed A tag requires to grab text from td
|
||||||
operation.raw=u''.join([txt.strip() for txt in td.itertext()])
|
raw=u''.join([txt.strip() for txt in td.itertext()])
|
||||||
elif value.startswith("solde") or value.startswith("mnt"):
|
elif value.startswith("solde") or value.startswith("mnt"):
|
||||||
mntColumn+=1
|
mntColumn+=1
|
||||||
amount=u''.join([txt.strip() for txt in td.itertext()])
|
amount=u''.join([txt.strip() for txt in td.itertext()])
|
||||||
if amount != "":
|
if amount != "":
|
||||||
amount = Decimal(amount.replace('.','').replace(',','.').replace(u"\u00A0",'').replace(' ',''))
|
|
||||||
if value.startswith("soldeDeb") or mntColumn==1:
|
if value.startswith("soldeDeb") or mntColumn==1:
|
||||||
amount=-amount
|
debit = amount
|
||||||
operation.amount=amount
|
else:
|
||||||
|
credit = amount
|
||||||
|
|
||||||
|
operation=Transaction(len(operations))
|
||||||
|
operation.parse(date, raw)
|
||||||
|
operation.set_amount(credit, debit)
|
||||||
operations.append(operation)
|
operations.append(operation)
|
||||||
return operations
|
return operations
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue