def get_account(self, _id): if not _id.isdigit(): raise AccountNotFound() account = self.browser.get_account(_id) if account: return account else: raise AccountNotFound()
def get_account(self, id_): self.to_activity() if id_ not in self.page.accounts_ids(): raise AccountNotFound() else: self.to_activity(id_) return self.page.get_account()
def get_account(self, _id): with self.browser: account = self.browser.get_account(_id) if account: return account else: raise AccountNotFound()
def iter_history_statements(self, account): # To avoid ImportError during e.g. building modules list. from selenium.webdriver.common.keys import Keys from selenium.common.exceptions import MoveTargetOutOfBoundsException,\ ElementNotVisibleException self.start() if account.id != self._account_id(): raise AccountNotFound() self.wait('a#cmlink_ViewPastStmtLink')[0].click() opts = self.wait('option#currentStatementDateOptions') for i, opt in enumerate(opts): # We're interested only in finalized statements. if u'Unbilled' in opt.get_attribute('value'): continue self.wait('div#currentStatementsDate-button')[0].click() ul = self.wait('ul#currentStatementsDate-menu')[0] while True: try: self.wait('li#currentStatementDateOptions span')[i].click() break except (MoveTargetOutOfBoundsException, ElementNotVisibleException): ul.send_keys(Keys.ARROW_DOWN) self.wait('a#downloadCurrentStatements')[0].click() pdfname = self.wait_file('.pdf') pdfpath = os.path.join(self._downloads, pdfname) with open(pdfpath, 'rb') as f: parser = StatementParser(f.read()) os.remove(pdfpath) # Transactions in a statement can go in different order. ts = sorted(parser.read_transactions(), cmp=lambda t1, t2: cmp(t2.date, t1.date)) yield from ts self.finish()
def ischecked(self, _id): # remove prefix (CC-, LA-, ...) if "-" in _id: _id = _id.split('-')[1] try: option = self.doc.xpath('//input[@value="%s"]' % _id)[0] except: raise AccountNotFound() return option.attrib.get("checked") == "checked"
def submit_account(self, id): for account in self.iter_accounts(): if account.id == id: break else: raise AccountNotFound() form = self.get_form(name='DebitAccount') form['DebitAccount[debitAccountKey]'] = account._sender_id form.submit()
def get_lf_attributes(self, lfid): attributes = {} # values can be in JS var format but it's not mandatory param so we don't go to get the real value try: values = Regexp(Link('//a[contains(., "%s")]' % lfid[:-3].lstrip('0')), r'\((.*?)\)')(self.doc).replace(' ', '').replace('\'', '').split(',') except XPathNotFound: raise AccountNotFound('cannot find account id %s on life insurance site' % lfid) keys = Regexp(CleanText('//script'), r'consultationContrat\((.*?)\)')(self.doc).replace(' ', '').split(',') attributes = dict(zip(keys, values)) return attributes
def transfer(self, account, to, amount, reason=None): if isinstance(account, Account): account = account.id try: assert account.isdigit() assert to.isdigit() amount = Decimal(amount) except (AssertionError, ValueError): raise AccountNotFound() with self.browser: return self.browser.transfer(account, to, amount, reason)
def transfer(self, account, to, amount, reason=None): if isinstance(account, Account): account = account.id account = str(account).strip(string.letters) to = str(to).strip(string.letters) try: assert account.isdigit() assert to.isdigit() amount = Decimal(amount) except (AssertionError, ValueError): raise AccountNotFound() return self.browser.transfer(account, to, amount, reason)
def init_transfer(self, transfer, **kwargs): self.check_basic_transfer(transfer) account = self.get_account(transfer.account_id) if not account: raise AccountNotFound() recipients = list(self.iter_transfer_recipients(account)) if not recipients: raise TransferInvalidEmitter('The account cannot emit transfers') recipients = [ rcpt for rcpt in recipients if rcpt.id == transfer.recipient_id ] if len(recipients) == 0: raise TransferInvalidRecipient( 'The recipient cannot be used with the emitter account') assert len(recipients) == 1 self.page.submit_recipient(recipients[0]._tempid) assert self.transfer_charac.is_here() self.page.submit_info(transfer.amount, transfer.label, transfer.exec_date) assert self.transfer_confirm.is_here() if self.page.need_refresh(): # In some case we are not yet in the transfer_charac page, you need to refresh the page self.location(self.url) assert not self.page.need_refresh() ret = self.page.get_transfer() # at this stage, the site doesn't show the real ids/ibans, we can only guess if recipients[0].label != ret.recipient_label: if not recipients[0].label.startswith( '%s - ' % ret.recipient_label): # the label displayed here is just "<name>" # but in the recipients list it is "<name> - <bank>"... raise TransferError('Recipient label changed during transfer') ret.recipient_id = recipients[0].id ret.recipient_iban = recipients[0].iban if account.label != ret.account_label: raise TransferError('Account label changed during transfer') ret.account_id = account.id ret.account_iban = account.iban return ret
def get_bourse_account(self, account): self.bourse_login.go(id=account.id) # "login" to bourse page self.bourse.go() assert self.bourse.is_here() if self.page.password_required(): return self.logger.debug('searching account matching %r', account) for bourse_account in self.page.get_list(): self.logger.debug('iterating account %r', bourse_account) if bourse_account.id.startswith(account.id[3:]): return bourse_account else: raise AccountNotFound()
def transfer(self, account, to, amount, reason=None): if self.config['website'].get() != 'ppold': raise NotImplementedError() if isinstance(account, Account): account = account.id try: assert account.isdigit() assert to.isdigit() amount = Decimal(amount) except (AssertionError, ValueError): raise AccountNotFound() with self.browser: return self.browser.transfer(account, to, amount, reason)
def ischecked(self, account): id = account.id # remove prefix (CC-, LA-, ...) id = id[3:] option = self.document.xpath('//input[@value="%s"]' % id) if len(option) < 0: raise AccountNotFound() else: option = option[0] try: if option.attrib["checked"] == "checked": return True else: return False except: return False
def iter_history_recent(self, account): self.start() if account.id != self._account_id(): raise AccountNotFound() self._account_link().click() self.wait_ajax() for span in self.find('span.cM-maximizeButton'): span.click() for tr in self.find('tr.payments,tr.purchase'): trdata = lambda n: tr.find_element_by_css_selector( 'td.cT-bodyTableColumn%i span.cT-line1' % n).text treid = tr.get_attribute('id').replace('rowID', 'rowIDExt') tredata = {} for tre in self.find('tr#%s' % treid): labels = [x.text for x in tre.find_elements_by_css_selector( 'div.cT-labelItem')] values = [x.text for x in tre.find_elements_by_css_selector( 'div.cT-valueItem')] tredata = dict(zip(labels, values)) ref = tredata.get(u'Reference Number:', u'') tdate = trdata(1) pdate = tredata.get(u'Posted Date :', tdate) desc = clean_label(trdata(2)) amount = trdata(4) tdate = datetime.datetime.strptime(tdate, '%m-%d-%Y') pdate = datetime.datetime.strptime(pdate, '%m-%d-%Y') if amount.startswith(u'(') and amount.endswith(u')'): amount = AmTr.decimal_amount(amount[1:-1]) else: amount = -AmTr.decimal_amount(amount) trans = Transaction(ref) trans.date = tdate trans.rdate = pdate trans.type = Transaction.TYPE_UNKNOWN trans.raw = desc trans.label = desc trans.amount = amount yield trans self.finish()
def goto_spirica(self, account): assert account.type == Account.TYPE_LIFE_INSURANCE self.goto_lifeinsurance(account) if self.login.is_here(): self.logger.info('was logged out, relogging') # if we don't clear cookies, we may land on the wrong spirica page self.session.cookies.clear() self.spirica.session.cookies.clear() self.do_login() self.goto_lifeinsurance(account) if self.lifeinsurance_list.is_here(): self.logger.debug('multiple life insurances, searching for %r', account) # multiple life insurances: dedicated page to choose for insurance_account in self.page.iter_accounts(): self.logger.debug('testing %r', account) if insurance_account.id == account.id: self.location(insurance_account.url) assert self.lifeinsurance_iframe.is_here() break else: raise AccountNotFound( 'account was not found in the dedicated page') else: assert self.lifeinsurance_iframe.is_here() self.location(self.page.get_iframe()) if self.lifeinsurance_error.is_here(): self.home.go() self.logger.warning('life insurance site is unavailable') return False assert self.lifeinsurance_redir.is_here() redir = self.page.get_redir() assert redir account.url = self.absurl(redir) self.spirica.session.cookies.update(self.session.cookies) self.spirica.logged = True return True
def get_account(self, _id): account = self.browser.get_account(_id) if account: return account raise AccountNotFound()
def get_account(self, id): for account in self.get_accounts_list(): if account.id == id: return account raise AccountNotFound('Unable to find account: %s' % id)
def get_account(self, id_): innerId = self.to_accounts().inner_ids_dict().get(id_) if innerId: return self.to_account(innerId).account() raise AccountNotFound()
def get_account(self, _id): for account in self.iter_accounts(): if account.id == _id: return account raise AccountNotFound()
def get_account(self, num): for count, account in enumerate(self.iter_accounts_list()): if (count + 1) == int(num): return account raise AccountNotFound()
def get_account(self, id_): a = next(self.iter_accounts()) if (a.id != id_): raise AccountNotFound() return a
def get_account(self, id): try: return self.accounts[id] except KeyError: raise AccountNotFound('Unable to find account: %s' % id)
def get_account_for_history(self, _id): account = self.browser.get_account_for_history(_id) if account: return account raise AccountNotFound()