From f84e200e1586c0b203e5353a13cfdbf08e9c3f79 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Mon, 4 Feb 2013 18:33:23 +0100 Subject: [PATCH] paypal: Support "american" balance style Sources: http://i.imgur.com/rtcuMDa.jpg http://i.imgur.com/TNcLbPB.jpg --- modules/paypal/pages.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/paypal/pages.py b/modules/paypal/pages.py index 31ee3f92..b5cf7195 100644 --- a/modules/paypal/pages.py +++ b/modules/paypal/pages.py @@ -18,6 +18,7 @@ # along with weboob. If not, see . from decimal import Decimal +import re from weboob.tools.browser import BasePage, BrokenPageError from weboob.capabilities.bank import Account @@ -27,6 +28,23 @@ __all__ = ['LoginPage', 'AccountPage'] def clean_amount(text): + """ + >>> clean_amount('42') + Decimal('42') + >>> clean_amount('42,12') + Decimal('42.12') + >>> clean_amount('42.12') + Decimal('42.12') + >>> clean_amount('$42.12 USD') + Decimal('42.12') + >>> clean_amount('$12.442,12 USD') + Decimal('12442.12') + >>> clean_amount('$12,442.12 USD') + Decimal('12442.12') + """ + # Convert "American" UUU.CC format to "French" UUU,CC format + if re.search(r'\d\.\d\d(?: [A-Z]+)?$', text): + text = text.replace(',', ' ').replace('.', ',') return Decimal(FrenchTransaction.clean_amount(text))