Don't bother memoizing ISO data yet.
This commit is contained in:
parent
45a1e1b0df
commit
d26ba68f2c
1 changed files with 9 additions and 22 deletions
|
@ -41,39 +41,24 @@ class ISOCurrency:
|
||||||
|
|
||||||
|
|
||||||
def current_data_date():
|
def current_data_date():
|
||||||
if not _current_data_date:
|
one = etree.fromstring(read_binary("pricehist.resources", "list_one.xml"))
|
||||||
_readall()
|
return one.cssselect("ISO_4217")[0].attrib["Pblshd"]
|
||||||
return _current_data_date
|
|
||||||
|
|
||||||
|
|
||||||
def historical_data_date():
|
def historical_data_date():
|
||||||
if not _historical_data_date:
|
three = etree.fromstring(read_binary("pricehist.resources", "list_three.xml"))
|
||||||
_readall()
|
return three.cssselect("ISO_4217")[0].attrib["Pblshd"]
|
||||||
return _historical_data_date
|
|
||||||
|
|
||||||
|
|
||||||
def bycode():
|
def bycode():
|
||||||
if not _bycode:
|
result = {}
|
||||||
_readall()
|
|
||||||
return _bycode
|
|
||||||
|
|
||||||
|
|
||||||
_current_data_date = None
|
|
||||||
_historical_data_date = None
|
|
||||||
_bycode = {}
|
|
||||||
|
|
||||||
|
|
||||||
def _readall():
|
|
||||||
one = etree.fromstring(read_binary("pricehist.resources", "list_one.xml"))
|
one = etree.fromstring(read_binary("pricehist.resources", "list_one.xml"))
|
||||||
three = etree.fromstring(read_binary("pricehist.resources", "list_three.xml"))
|
three = etree.fromstring(read_binary("pricehist.resources", "list_three.xml"))
|
||||||
|
|
||||||
_current_data_date = one.cssselect("ISO_4217")[0].attrib["Pblshd"]
|
|
||||||
_historical_data_date = three.cssselect("ISO_4217")[0].attrib["Pblshd"]
|
|
||||||
(_current_data_date, _historical_data_date) # No-op
|
|
||||||
|
|
||||||
for entry in three.cssselect("HstrcCcyNtry") + one.cssselect("CcyNtry"):
|
for entry in three.cssselect("HstrcCcyNtry") + one.cssselect("CcyNtry"):
|
||||||
if currency := _parse(entry):
|
if currency := _parse(entry):
|
||||||
if existing := _bycode.get(currency.code):
|
if existing := result.get(currency.code):
|
||||||
existing.code = currency.code
|
existing.code = currency.code
|
||||||
existing.number = currency.number
|
existing.number = currency.number
|
||||||
existing.minor_units = currency.minor_units
|
existing.minor_units = currency.minor_units
|
||||||
|
@ -83,7 +68,9 @@ def _readall():
|
||||||
existing.historical = currency.historical
|
existing.historical = currency.historical
|
||||||
existing.withdrawal_date = currency.withdrawal_date
|
existing.withdrawal_date = currency.withdrawal_date
|
||||||
else:
|
else:
|
||||||
_bycode[currency.code] = currency
|
result[currency.code] = currency
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _parse(entry):
|
def _parse(entry):
|
||||||
|
|
Loading…
Add table
Reference in a new issue