From 9aa27eb225e7f2ac8a916d0d1a1b0d2c4082dae9 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Fri, 11 Jan 2013 19:07:49 +0100 Subject: [PATCH] fix support of deferred transactions --- modules/barclays/backend.py | 8 ++++++-- modules/barclays/browser.py | 8 ++++++-- modules/barclays/pages.py | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/barclays/backend.py b/modules/barclays/backend.py index f286af66..d1124da7 100644 --- a/modules/barclays/backend.py +++ b/modules/barclays/backend.py @@ -60,8 +60,12 @@ class BarclaysBackend(BaseBackend, ICapBank): def iter_history(self, account): with self.browser: - return self.browser.get_history(account) + for tr in self.browser.get_history(account): + if not tr._coming: + yield tr def iter_coming(self, account): with self.browser: - return self.browser.get_coming_operations(account) + for tr in self.browser.get_card_operations(account): + if tr._coming: + yield tr diff --git a/modules/barclays/browser.py b/modules/barclays/browser.py index 136dbec5..d491b3d3 100644 --- a/modules/barclays/browser.py +++ b/modules/barclays/browser.py @@ -103,9 +103,13 @@ class Barclays(BaseBrowser): assert self.is_on_page((TransactionsPage, ValuationPage, LoanPage)) - return self.page.get_history() + for tr in self.page.get_history(): + yield tr - def get_coming_operations(self, account): + for tr in self.get_card_operations(account): + yield tr + + def get_card_operations(self, account): for card in account._card_links: if not self.is_on_page(AccountsPage): self.location('tbord.do') diff --git a/modules/barclays/pages.py b/modules/barclays/pages.py index 3a413a96..21be4895 100644 --- a/modules/barclays/pages.py +++ b/modules/barclays/pages.py @@ -142,6 +142,7 @@ class TransactionsPage(BasePage): credit = u''.join([txt.strip() for txt in tds[-2].itertext()]) t.parse(date, re.sub(r'[ ]+', ' ', raw)) t.set_amount(credit, debit) + t._coming = False if t.raw.startswith('ACHAT CARTE -DEBIT DIFFERE'): continue @@ -152,6 +153,7 @@ class TransactionsPage(BasePage): class CardPage(BasePage): def get_history(self): debit_date = None + coming = True for tr in self.document.xpath('//table[@class="report"]/tbody/tr'): tds = tr.findall('td') @@ -159,6 +161,8 @@ class CardPage(BasePage): # headers m = re.match('.* (\d+)/(\d+)/(\d+)', tds[0].text.strip()) debit_date = datetime.date(int(m.group(3)), int(m.group(2)), int(m.group(1))) + if debit_date < datetime.date.today(): + coming = False if len(tds) != 3: continue @@ -172,6 +176,7 @@ class CardPage(BasePage): t.date = debit_date t.label = unicode(tds[1].find('span').text.strip()) t.type = t.TYPE_CARD + t._coming = coming t.set_amount(amount) yield t