def get_list(self, pro=True): accounts = [] for tr in self.document.xpath('//tr[@class="comptes"]'): cols = tr.findall('td') if len(cols) < 5: continue account = Account() account.id = self.parser.tocleanstring(cols[self.COL_ID]).replace( " ", "") account.label = self.parser.tocleanstring(cols[self.COL_LABEL]) account.balance = Decimal( self.parser.tocleanstring(cols[self.COL_BALANCE])) try: account.coming = Decimal( self.parser.tocleanstring(cols[self.COL_COMING])) except InvalidOperation: if self.parser.tocleanstring(cols[self.COL_COMING]) != '-': self.logger.warning('Unable to parse coming value', exc_info=True) account.coming = NotAvailable account._link_id = None account._stp = None a = cols[self.COL_LABEL].find('a') if a is not None: url = urlparse(a.attrib['href']) p = dict(parse_qsl(url.query)) account._link_id = p.get('ch4', None) account._stp = p.get('stp', None) accounts.append(account) # If there are also personnal accounts linked, display the page and iter on them. if pro and len( self.document.xpath( '//div[@class="onglets"]//a[contains(@href, "afficherComptesPrives")]' )) > 0: self.browser.select_form(name='myForm') self.browser.set_all_readonly(False) self.browser['udcAction'] = '/afficherComptesPrives' self.browser.submit() for a in self.browser.page.get_list(False): accounts.append(a) return accounts
def _parse_account(self, tr): account = Account() # for pro usage account._stp = None account.id = tr.xpath('.//td[@class="libelleCompte"]/input' )[0].attrib['id'][len('libelleCompte'):] if len(str(account.id)) == 23: account.id = str(account.id)[5:21] a = tr.xpath('.//td[@class="libelleCompte"]/a')[0] m = re.match(r'javascript:goToStatements\(\'(\d+)\'', a.get('onclick', '')) if m: account._link_id = m.group(1) else: # Can't get history for this account. account._link_id = None # To prevent multiple-IDs for CIF (for example), add an arbitrary char in ID. account.id += 'C' account.label = u'' + a.text.strip() tds = tr.findall('td') account.currency = account.get_currency(tds[3].find('a').text) account.balance = self._parse_amount(tds[3].find('a')) if tds[4].find('a') is not None: account.coming = self._parse_amount(tds[4].find('a')) else: account.coming = NotAvailable return account
def _parse_account(self, tr): account = Account() # for pro usage account._stp = None account.id = tr.xpath('.//td[@class="libelleCompte"]/input')[0].attrib['id'][len('libelleCompte'):] if len(str(account.id)) == 23: account.id = str(account.id)[5:21] a = tr.xpath('.//td[@class="libelleCompte"]/a')[0] m = re.match(r'javascript:goToStatements\(\'(\d+)\'', a.get('onclick', '')) if m: account._link_id = m.group(1) else: # Can't get history for this account. account._link_id = None # To prevent multiple-IDs for CIF (for example), add an arbitrary char in ID. account.id += 'C' account.label = u''+a.text.strip() tds = tr.findall('td') account.currency = account.get_currency(tds[3].find('a').text) account.balance = self._parse_amount(tds[3].find('a')) if tds[4].find('a') is not None: account.coming = self._parse_amount(tds[4].find('a')) else: account.coming = NotAvailable return account
def get_list(self, pro=True): accounts = [] for tr in self.document.xpath('//tr[@class="comptes"]'): cols = tr.findall('td') if len(cols) < 5: continue account = Account() account.id = self.parser.tocleanstring(cols[self.COL_ID]).replace(" ", "") account.label = self.parser.tocleanstring(cols[self.COL_LABEL]) account.balance = Decimal(self.parser.tocleanstring(cols[self.COL_BALANCE])) try: account.coming = Decimal(self.parser.tocleanstring(cols[self.COL_COMING])) except InvalidOperation: if self.parser.tocleanstring(cols[self.COL_COMING]) != '-': self.logger.warning('Unable to parse coming value', exc_info=True) account.coming = NotAvailable account._link_id = None account._stp = None a = cols[self.COL_LABEL].find('a') if a is not None: url = urlparse(a.attrib['href']) p = dict(parse_qsl(url.query)) account._link_id = p.get('ch4', None) account._stp = p.get('stp', None) for input_tag in tr.xpath('.//input[starts-with(@id, "urlRib")]'): m = re.search('ch4=(\w+)', input_tag.get('value', '')) if m: account.iban = unicode(m.group(1)) accounts.append(account) # If there are also personnal accounts linked, display the page and iter on them. if pro and len(self.document.xpath('//div[@class="onglets"]//a[contains(@href, "afficherComptesPrives")]')) > 0: self.browser.select_form(name='myForm') self.browser.set_all_readonly(False) self.browser['udcAction'] = '/afficherComptesPrives' self.browser.submit() for a in self.browser.page.get_list(False): accounts.append(a) return accounts
def get_list(self, pro=True): accounts = [] for tr in self.document.xpath('//tr[@class="comptes"]'): cols = tr.findall('td') if len(cols) < 5: continue account = Account() account.id = self.parser.tocleanstring(cols[self.COL_ID]).replace( " ", "") account.label = self.parser.tocleanstring(cols[self.COL_LABEL]) account.balance = Decimal( self.parser.tocleanstring(cols[self.COL_BALANCE])) try: account.coming = Decimal( self.parser.tocleanstring(cols[self.COL_COMING])) except InvalidOperation: if self.parser.tocleanstring(cols[self.COL_COMING]) != '-': self.logger.warning('Unable to parse coming value', exc_info=True) account.coming = NotAvailable account._link_id = None account._stp = None a = cols[self.COL_LABEL].find('a') if a is not None: url = urlparse(a.attrib['href']) p = dict(parse_qsl(url.query)) account._link_id = p.get('ch4', None) account._stp = p.get('stp', None) for input_tag in tr.xpath('.//input[starts-with(@id, "urlRib")]'): m = re.search('ch4=(\w+)', input_tag.get('value', '')) if m: account.iban = unicode(m.group(1)) break else: select = tr.xpath('.//select//@onchange')[0] m = re.search("\(this,'(\w+)", select) if m: iban = unicode(m.group(1)) if iban.startswith('FR') and len(iban) == 27: account.iban = unicode(m.group(1)) accounts.append(account) # If there are also personnal accounts linked, display the page and iter on them. if pro and len( self.document.xpath( '//div[@class="onglets"]//a[contains(@href, "afficherComptesPrives")]' )) > 0: self.browser.select_form(name='myForm') self.browser.set_all_readonly(False) self.browser['udcAction'] = '/afficherComptesPrives' self.browser.submit() for a in self.browser.page.get_list(False): accounts.append(a) return accounts