diff --git a/modules/paypal/backend.py b/modules/paypal/backend.py index fa6ec03e..3cfb3cf9 100644 --- a/modules/paypal/backend.py +++ b/modules/paypal/backend.py @@ -47,7 +47,8 @@ class PaypalBackend(BaseBackend, ICapBank): self.config['password'].get()) def iter_accounts(self): - yield self.get_account(u"1") + for account in self.browser.get_accounts(): + yield account def get_account(self, _id): with self.browser: diff --git a/modules/paypal/browser.py b/modules/paypal/browser.py index 630e0674..6c04dd8f 100644 --- a/modules/paypal/browser.py +++ b/modules/paypal/browser.py @@ -55,6 +55,9 @@ class Paypal(BaseBrowser): if self.is_on_page(LoginPage): raise BrowserIncorrectPassword() + def get_accounts(self): + yield self.get_account(u"1") + def get_account(self, _id): if _id != u"1": return None @@ -62,7 +65,7 @@ class Paypal(BaseBrowser): if not self.is_on_page(AccountPage): self.location('/en/cgi-bin/webscr?cmd=_account&nav=0.0') - return self.page.get_account() + return self.page.get_account(_id) def get_history(self, account): raise NotImplementedError() diff --git a/modules/paypal/pages.py b/modules/paypal/pages.py index d232fe8f..37d7eb55 100644 --- a/modules/paypal/pages.py +++ b/modules/paypal/pages.py @@ -26,6 +26,10 @@ from weboob.tools.capabilities.bank.transactions import FrenchTransaction __all__ = ['LoginPage', 'AccountPage'] +def clean_amount(text): + return Decimal(FrenchTransaction.clean_amount(text)) + + class LoginPage(BasePage): def login(self, login, password): self.browser.select_form(name='login_form') @@ -35,16 +39,30 @@ class LoginPage(BasePage): class AccountPage(BasePage): - def get_account(self): + def get_account(self, _id): + assert _id == u"1" # Only one "account" supported for now + account = Account() - account.id = u"1" + account.id = _id account.label = unicode(self.browser.username) account.type = Account.TYPE_CHECKING - balance = self.document.xpath('//div[@id="main"]')[0] \ - .xpath('.//div[@class="col first"]//h3/span[@class="balance"]')[0] \ - .balance.text_content().strip() - account.balance = Decimal(FrenchTransaction.clean_amount(balance)) + content = self.document.xpath('//div[@id="main"]//div[@class="col first"]')[0] + # Total currency balance. + # If there are multiple currencies, this balance is all currencies + # converted to the main currency. + balance = content.xpath('//h3/span[@class="balance"]')[0].text_content().strip() + account.balance = clean_amount(balance) account.currency = account.get_currency(balance) + # Primary currency balance. + # If the user enabled multiple currencies, we get this one instead. + # An Account object has only one currency; secondary currencies should be other accounts. + balance = content.xpath('//div[@class="body"]//ul/li[@class="balance"]/span') + if balance: + balance = balance[0].text_content().strip() + account.balance = clean_amount(balance) + # The primary currency of the "head balance" is the same; ensure we got the right one + assert account.currency == account.get_currency(balance) + return account