Move Currency from ICapBank to ICapBase
This commit is contained in:
parent
f940bf42ac
commit
4d5b84a2a8
3 changed files with 52 additions and 50 deletions
|
|
@ -23,7 +23,8 @@ from datetime import date, timedelta
|
||||||
import re
|
import re
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from weboob.capabilities.bank import Account, Currency, Transaction
|
from weboob.capabilities.base import Currency
|
||||||
|
from weboob.capabilities.bank import Account, Transaction
|
||||||
from weboob.capabilities.base import NotAvailable
|
from weboob.capabilities.base import NotAvailable
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ from binascii import crc32
|
||||||
|
|
||||||
from weboob.tools.ordereddict import OrderedDict
|
from weboob.tools.ordereddict import OrderedDict
|
||||||
|
|
||||||
from .base import CapBaseObject, Field, StringField, DateField, DecimalField, IntField, UserError
|
from .base import CapBaseObject, Field, StringField, DateField, DecimalField, IntField, UserError, Currency
|
||||||
from .collection import ICapCollection
|
from .collection import ICapCollection
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -46,54 +46,6 @@ class TransferError(UserError):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
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),
|
|
||||||
))
|
|
||||||
|
|
||||||
EXTRACTOR = re.compile(r'[\d\s,\.\-]', re.UNICODE)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_currency(klass, text):
|
|
||||||
u"""
|
|
||||||
>>> Currency.get_currency(u'42')
|
|
||||||
0
|
|
||||||
>>> Currency.get_currency(u'42 €')
|
|
||||||
1
|
|
||||||
>>> Currency.get_currency(u'$42')
|
|
||||||
3
|
|
||||||
>>> Currency.get_currency(u'42.000,00€')
|
|
||||||
1
|
|
||||||
>>> Currency.get_currency(u'$42 USD')
|
|
||||||
3
|
|
||||||
>>> Currency.get_currency(u'%42 USD')
|
|
||||||
3
|
|
||||||
>>> Currency.get_currency(u'US1D')
|
|
||||||
0
|
|
||||||
"""
|
|
||||||
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
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def currency2txt(klass, currency):
|
|
||||||
for txt, value in klass.TXT2CUR.iteritems():
|
|
||||||
if value == currency:
|
|
||||||
return txt
|
|
||||||
return u''
|
|
||||||
|
|
||||||
|
|
||||||
class Recipient(CapBaseObject):
|
class Recipient(CapBaseObject):
|
||||||
"""
|
"""
|
||||||
Recipient of a transfer.
|
Recipient of a transfer.
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
import datetime
|
import datetime
|
||||||
|
import re
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from copy import deepcopy, copy
|
from copy import deepcopy, copy
|
||||||
|
|
||||||
|
|
@ -424,3 +425,51 @@ class CapBaseObject(object):
|
||||||
|
|
||||||
fields_iterator = self.iter_fields()
|
fields_iterator = self.iter_fields()
|
||||||
return OrderedDict(iter_decorate(fields_iterator))
|
return OrderedDict(iter_decorate(fields_iterator))
|
||||||
|
|
||||||
|
|
||||||
|
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),
|
||||||
|
))
|
||||||
|
|
||||||
|
EXTRACTOR = re.compile(r'[\d\s,\.\-]', re.UNICODE)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_currency(klass, text):
|
||||||
|
u"""
|
||||||
|
>>> Currency.get_currency(u'42')
|
||||||
|
0
|
||||||
|
>>> Currency.get_currency(u'42 €')
|
||||||
|
1
|
||||||
|
>>> Currency.get_currency(u'$42')
|
||||||
|
3
|
||||||
|
>>> Currency.get_currency(u'42.000,00€')
|
||||||
|
1
|
||||||
|
>>> Currency.get_currency(u'$42 USD')
|
||||||
|
3
|
||||||
|
>>> Currency.get_currency(u'%42 USD')
|
||||||
|
3
|
||||||
|
>>> Currency.get_currency(u'US1D')
|
||||||
|
0
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def currency2txt(klass, currency):
|
||||||
|
for txt, value in klass.TXT2CUR.iteritems():
|
||||||
|
if value == currency:
|
||||||
|
return txt
|
||||||
|
return u''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue