Commit 9123bcf4 authored by David Kremer's avatar David Kremer Committed by Romain Bignon

[ing] list cards and set category to deferred

Make the list of card associated with the user
logged on the site. Set all the CB transactions
to cb_deferred if all the CB are of kind
'deferred'
parent 0903b196
......@@ -28,6 +28,7 @@ from weboob.exceptions import BrowserIncorrectPassword
from weboob.browser.exceptions import ServerError
from weboob.capabilities.bank import Account, AccountNotFound
from weboob.capabilities.base import find_object
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
from .pages import AccountsList, LoginPage, NetissimaPage, TitrePage, TitreHistory,\
TransferPage, BillsPage, StopPage, TitreDetails, TitreValuePage, ASVHistory,\
......@@ -61,7 +62,8 @@ def start_with_main_site(f):
class IngBrowser(LoginBrowser):
BASEURL = 'https://secure.ingdirect.fr'
TIMEOUT = 60.0
DEFERRED_CB = 'deferred'
IMMEDIATE_CB = 'immediate'
# avoid relogin every time
lifeback = URL(r'https://ingdirectvie.ingdirect.fr/b2b2c/entreesite/EntAccExit', ReturnPage)
......@@ -102,6 +104,7 @@ class IngBrowser(LoginBrowser):
LoginBrowser.__init__(self, *args, **kwargs)
self.cache = {}
self.cache["investments_data"] = {}
self.only_deferred_cards = {}
def do_login(self):
assert self.password.isdigit()
......@@ -169,6 +172,11 @@ class IngBrowser(LoginBrowser):
"cptnbr": account._id
}
self.accountspage.go(data=data)
card_list = self.page.get_card_list()
if card_list:
self.only_deferred_cards[account._id] = any(
[card['kind'] != self.DEFERRED_CB for card in card_list]
)
self.where = "history"
@need_login
......@@ -201,6 +209,8 @@ class IngBrowser(LoginBrowser):
account = self.get_account(account.id)
self.go_account_page(account)
jid = self.page.get_history_jid()
only_deferred_cb = self.only_deferred_cards.get(account._id)
if jid is None:
self.logger.info('There is no history for this account')
return
......@@ -215,6 +225,9 @@ class IngBrowser(LoginBrowser):
while True:
i = index
for transaction in history_function(self.page, index=index):
if only_deferred_cb and transaction.type == FrenchTransaction.TYPE_CARD:
transaction.type = FrenchTransaction.TYPE_DEFERRED_CARD
transaction.id = hashlib.md5(transaction._hash).hexdigest()
while transaction.id in hashlist:
transaction.id = hashlib.md5((transaction.id + "1").encode('ascii')).hexdigest()
......
......@@ -26,9 +26,12 @@ from weboob.capabilities.bank import Account, Investment
from weboob.capabilities.base import NotAvailable
from weboob.capabilities.profile import Person
from weboob.browser.pages import HTMLPage, LoggedPage
from weboob.browser.elements import ListElement, TableElement, ItemElement, method
from weboob.browser.filters.standard import CleanText, CleanDecimal, Filter, Field, MultiFilter, Date, \
Lower, Async, AsyncLoad, Format, TableCell, Eval, Env
from weboob.browser.elements import ListElement, TableElement, ItemElement, method, DataError
from weboob.browser.filters.standard import (
CleanText, CleanDecimal, Filter, Field, MultiFilter, Date,
Lower, Async, AsyncLoad, Format, TableCell, Eval, Env,
Regexp,
)
from weboob.browser.filters.html import Attr, Link
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
......@@ -129,6 +132,29 @@ class AccountsList(LoggedPage, HTMLPage):
def has_link(self):
return len(self.doc.xpath('//a[contains(@href, "goTo")]'))
def get_card_list(self):
card_list = []
card_elements = self.doc.xpath('//div[has-class("ccinc_cards")]/div[has-class("accordion")]')
for card in card_elements:
card_properties = {}
card_properties['number'] = Regexp(CleanText('.'), '([0-9]{4}\s\*{4}\s\*{4}\s[0-9]{4})')(card)
debit_info = (CleanText('.//div[@class="debit-info"]', default='')(card))
is_deferred = debit_info.startswith('Débit différé')
is_immediate = debit_info.startswith('Débit immédiat')
if is_immediate:
card_properties['kind'] = self.browser.IMMEDIATE_CB
elif is_deferred:
card_properties['kind'] = self.browser.DEFERRED_CB
else:
raise DataError("Cannot tell if this card is deferred or immediate")
card_list.append(card_properties)
return card_list
@method
class get_list(ListElement):
item_xpath = '//a[@class="mainclic"]'
......
......@@ -19,7 +19,7 @@
from weboob.tools.test import BackendTest
from weboob.capabilities.bank import Account
from weboob.capabilities.bank import Account, Transaction
from datetime import timedelta
import random
......@@ -35,8 +35,8 @@ class INGTest(BackendTest):
self.assertTrue(_id.id == account.id)
# Methods can use Account objects or id. Try one of them
id_or_account = random.choice([account, account.id])
history = list(self.backend.iter_history(id_or_account))
if account.type == Account.TYPE_CHECKING or account.type == Account.TYPE_SAVINGS:
history = list(self.backend.iter_history(id_or_account))
self.assertTrue(len(history) > 0)
date = history[0].date
for elem in history[1:]:
......@@ -53,6 +53,9 @@ class INGTest(BackendTest):
invest = list(self.backend.iter_investment(id_or_account))
self.backend.iter_history(id_or_account) # can be empty. Only try to call it
self.assertTrue(len(invest) > 0)
deferred_cards_only = self.browser.only_deferred_cards.get(account._id)
if deferred_cards_only:
self.assertTrue(all([transaction.type != Transaction.TYPE_CARD for transaction in history]))
def test_subscriptions(self):
l = list(self.backend.iter_subscription())
......
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