From 5ebc341b4f4ef3c6beac1c50c725938c1361ad87 Mon Sep 17 00:00:00 2001 From: Benjamin Tampigny Date: Wed, 16 Dec 2020 17:11:39 +0100 Subject: [PATCH] [cragr] don't crash if subscription is found multiple times This can happen because it is displayed twice (bank statement + deffered statements). But the attributes of the subscription were the same. Before this changes, the duplicates were supposed to be handled by the variable parsed_subscription_ids but its values were given only at the first iteration, so it was just an empty list and the condition was always True. Since the regexp which get some information on the subscription is now used once per subscription, there were no need to make a method of it. --- modules/cragr/browser.py | 6 +----- modules/cragr/document_pages.py | 15 +++++---------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/modules/cragr/browser.py b/modules/cragr/browser.py index 0fa032db76..46c010dc80 100644 --- a/modules/cragr/browser.py +++ b/modules/cragr/browser.py @@ -1290,9 +1290,6 @@ def iter_subscription(self): # We have been logged out. self.do_login() - # Some subscriptions exist in 2 occurences in the page: e.g. one account has regular bank statement reports + deffered statements - # We use this variable not to parse a subscription twice and cause trouble - parsed_subscription_ids = [] for contract in self.iter_spaces(): self.token_page.go() token = self.page.get_token() @@ -1303,9 +1300,8 @@ def iter_subscription(self): except HTTPNotFound: continue self.page.submit(token) - for sub in self.page.iter_subscription(parsed_subscription_ids=parsed_subscription_ids): + for sub in self.page.iter_subscription(): sub._contract = contract - parsed_subscription_ids.append(sub.id) yield sub @need_login diff --git a/modules/cragr/document_pages.py b/modules/cragr/document_pages.py index d6657fd71e..2e07749dff 100644 --- a/modules/cragr/document_pages.py +++ b/modules/cragr/document_pages.py @@ -43,25 +43,20 @@ def has_error(self): @method class iter_subscription(ListElement): + # Some subscriptions exist in 2 occurences in the page: e.g. one account has regular bank statement reports + deffered statements + # there might be duplicate, but not a big deal weboob is good and will keep only one subscription. + ignore_duplicate = True item_xpath = '//div[contains(text(), "RELEVES DE COMPTES")]/following-sibling::table//tr//div[contains(@class, "table")]' class item(ItemElement): klass = Subscription - def get_account_information(self): + def parse(self, el): raw = CleanText('./a')(self) # raw = account_name account_id account_owner m = re.match(r'([A-Za-z ]+) (\d+) (.+)$', raw) assert m, 'Format of line is not: ACT 123456789 M. First Last' - return m.groups() - - def condition(self): - # We check if the subscription hasn't been already parsed - _, account_id, _ = self.get_account_information() - return account_id not in Env('parsed_subscription_ids')(self) - - def parse(self, el): - self.env['account_name'], self.env['account_id'], self.env['account_owner'] = self.get_account_information() + self.env['account_name'], self.env['account_id'], self.env['account_owner'] = m.groups() obj_label = Format('%s %s', Env('account_name'), Env('account_owner')) obj_subscriber = Env('account_owner') -- GitLab