diff --git a/modules/citelis/browser.py b/modules/citelis/browser.py index 25d2793c..582226c9 100644 --- a/modules/citelis/browser.py +++ b/modules/citelis/browser.py @@ -61,7 +61,7 @@ class CitelisBrowser(BaseBrowser): self.location('%s://%s/summarySearch.do?reqCode=search' % (self.PROTOCOL, self.DOMAIN)) account = Account() account.id = u'1' - account.currency = Account.CUR_EUR + account.currency = 'EUR' account.balance = self.page.get_balance() account.label = u'Synthèse financière' return [account] diff --git a/modules/delubac/pages.py b/modules/delubac/pages.py index 616423ac..a56627a1 100644 --- a/modules/delubac/pages.py +++ b/modules/delubac/pages.py @@ -65,8 +65,7 @@ class DashboardPage(BasePage): account.balance = Decimal(FrenchTransaction.clean_amount( get_field('accountTotal'))) account.label = get_field('accountLabel2') - account.currency = Account.TXT2CUR.get(get_field('accountDev'), - Account.CUR_UNKNOWN) + account.currency = account.get_currency(get_field('accountDev')) return account diff --git a/modules/ing/pages/accounts_list.py b/modules/ing/pages/accounts_list.py index 7cf0b71d..b9ca4712 100644 --- a/modules/ing/pages/accounts_list.py +++ b/modules/ing/pages/accounts_list.py @@ -23,7 +23,6 @@ from datetime import date, timedelta import re import hashlib -from weboob.capabilities.base import Currency from weboob.capabilities.bank import Account, Transaction from weboob.capabilities.base import NotAvailable from weboob.tools.browser import BasePage @@ -59,7 +58,7 @@ class AccountsList(BasePage): # TODO: no idea abount how proxy account are displayed for a in self.document.xpath('//a[@class="mainclic"]'): account = Account() - account.currency = Currency.CUR_EUR + account.currency = 'EUR' account.id = unicode(a.find('span[@class="account-number"]').text) account._id = account.id account.label = unicode(a.find('span[@class="title"]').text) diff --git a/modules/leclercmobile/backend.py b/modules/leclercmobile/backend.py index cc94542b..f5f7a2ec 100644 --- a/modules/leclercmobile/backend.py +++ b/modules/leclercmobile/backend.py @@ -22,7 +22,6 @@ from weboob.capabilities.bill import ICapBill, SubscriptionNotFound,\ BillNotFound, Subscription, Bill from weboob.tools.backend import BaseBackend, BackendConfig -from weboob.capabilities.base import Currency from weboob.tools.value import ValueBackendPassword from .browser import Leclercmobile @@ -106,5 +105,5 @@ class LeclercMobileBackend(BaseBackend, ICapBill): balance = self.browser.get_balance() balance.label = u"Balance %s" % subscription.id balance.id = "%s-balance" % subscription.id - balance.currency = Currency.CUR_EUR + balance.currency = 'EUR' return balance diff --git a/modules/nettokom/backend.py b/modules/nettokom/backend.py index 5feeff15..c20b6207 100644 --- a/modules/nettokom/backend.py +++ b/modules/nettokom/backend.py @@ -20,7 +20,6 @@ from weboob.capabilities.bill import ICapBill, Subscription, SubscriptionNotFound, Detail -from weboob.capabilities.base import Currency from weboob.tools.backend import BaseBackend, BackendConfig from weboob.tools.value import ValueBackendPassword @@ -80,5 +79,5 @@ class NettoKomBackend(BaseBackend, ICapBill): balance.id = "%s-balance" % subscription.id balance.price = subscription._balance balance.label = u"Balance %s" % subscription.id - balance.currency = Currency.CUR_EUR + balance.currency = 'EUR' return balance diff --git a/modules/poivy/backend.py b/modules/poivy/backend.py index bd076511..fe376441 100644 --- a/modules/poivy/backend.py +++ b/modules/poivy/backend.py @@ -19,7 +19,6 @@ from weboob.capabilities.bill import ICapBill, Subscription, SubscriptionNotFound, Detail -from weboob.capabilities.base import Currency from weboob.tools.backend import BaseBackend, BackendConfig from weboob.tools.value import ValueBackendPassword @@ -76,5 +75,5 @@ class PoivyBackend(BaseBackend, ICapBill): balance.id = "%s-balance" % subscription.id balance.price = subscription._balance balance.label = u"Balance %s" % subscription.id - balance.currency = Currency.CUR_EUR + balance.currency = 'EUR' return balance diff --git a/modules/poivy/pages.py b/modules/poivy/pages.py index 23ddd726..2e916bb5 100644 --- a/modules/poivy/pages.py +++ b/modules/poivy/pages.py @@ -18,7 +18,6 @@ # along with weboob. If not, see . from weboob.tools.browser import BasePage -from weboob.capabilities.base import Currency from weboob.capabilities.bill import Subscription, Detail from decimal import Decimal, InvalidOperation from datetime import datetime, date, time @@ -106,7 +105,7 @@ class HistoryPage(BasePage): detail.price = Decimal(price) except InvalidOperation: detail.price = Decimal(0) # free calls - detail.currency = Currency.CUR_EUR + detail.currency = 'EUR' yield detail diff --git a/weboob/capabilities/bank.py b/weboob/capabilities/bank.py index 288e1035..b2a32280 100644 --- a/weboob/capabilities/bank.py +++ b/weboob/capabilities/bank.py @@ -49,8 +49,8 @@ class Recipient(CapBaseObject, Currency): Recipient of a transfer. """ - label = StringField('Name') - currency = IntField('Currency', default=Currency.CUR_UNKNOWN) + label = StringField('Name') + currency = StringField('Currency', default=None) def __init__(self): CapBaseObject.__init__(self, 0) diff --git a/weboob/capabilities/base.py b/weboob/capabilities/base.py index 1683f112..fade3780 100644 --- a/weboob/capabilities/base.py +++ b/weboob/capabilities/base.py @@ -428,17 +428,11 @@ class CapBaseObject(object): class Currency(object): - CUR_UNKNOWN = 0 - CUR_EUR = 1 - CUR_CHF = 2 - CUR_USD = 3 - - TXT2CUR = OrderedDict(((u'€', CUR_EUR), - (u'EUR', CUR_EUR), - (u'CHF', CUR_CHF), - (u'$', CUR_USD), - (u'USD', CUR_USD), - )) + CURRENCIES = {u'EUR': u'€', + u'CHF': u'CHF', + u'USD': u'$', + u'GBP': u'£', + } EXTRACTOR = re.compile(r'[\d\s,\.\-]', re.UNICODE) @@ -462,14 +456,11 @@ class Currency(object): """ curtexts = klass.EXTRACTOR.sub(' ', text.upper()).split() for curtext in curtexts: - cur = klass.TXT2CUR.get(curtext) - if cur is not None: - return cur - return klass.CUR_UNKNOWN + for currency, symbol in klass.CURRENCIES.iteritems(): + if curtext in (currency, symbol): + return currency + return None @classmethod def currency2txt(klass, currency): - for txt, value in klass.TXT2CUR.iteritems(): - if value == currency: - return txt - return u'' + return klass.CURRENCIES.get(currency, u'') diff --git a/weboob/capabilities/bill.py b/weboob/capabilities/bill.py index a1bc450a..9c140bfa 100644 --- a/weboob/capabilities/bill.py +++ b/weboob/capabilities/bill.py @@ -18,7 +18,7 @@ # along with weboob. If not, see . -from .base import CapBaseObject, StringField, DateField, DecimalField, IntField, UserError, Currency +from .base import CapBaseObject, StringField, DateField, DecimalField, UserError from .collection import ICapCollection @@ -50,7 +50,7 @@ class Detail(CapBaseObject): datetime = DateField('date information') price = DecimalField('Total price, taxes included') vat = DecimalField('Value added Tax') - currency = IntField('Currency', default=Currency.CUR_UNKNOWN) + currency = StringField('Currency', default=None) quantity = DecimalField('Number of units consumed') unit = StringField('Unit of the consumption') @@ -67,7 +67,7 @@ class Bill(CapBaseObject): label = StringField('label of bill') idparent = StringField('id of the parent subscription') price = DecimalField('Price to pay') - currency = IntField('Currency', default=Currency.CUR_UNKNOWN) + currency = StringField('Currency', default=None) deadline = DateField('The latest day to pay') startdate = DateField('The first day the bill applies to') finishdate = DateField('The last day the bill applies to') diff --git a/weboob/capabilities/travel.py b/weboob/capabilities/travel.py index 442f1288..2709a341 100644 --- a/weboob/capabilities/travel.py +++ b/weboob/capabilities/travel.py @@ -21,7 +21,7 @@ import datetime from .base import IBaseCap, CapBaseObject, StringField, TimeField, DeltaField, \ - DateField, DecimalField, IntField, Currency, UserError + DateField, DecimalField, UserError __all__ = ['Station', 'Departure', 'RoadStep', 'RoadmapError', 'RoadmapFilters', 'ICapTravel'] @@ -54,7 +54,7 @@ class Departure(CapBaseObject): information = StringField('Informations') plateform = StringField('Where the train will leave') price = DecimalField('Price of ticket') - currency = IntField('Currency', default=Currency.CUR_UNKNOWN) + currency = StringField('Currency', default=None) def __init__(self, id, _type, _time): CapBaseObject.__init__(self, id)