Use non-deprecated importlib_resources API.
This commit is contained in:
parent
7f4ed2f8b5
commit
34c503f6cb
2 changed files with 26 additions and 13 deletions
|
@ -24,7 +24,7 @@ Functions:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from importlib.resources import read_binary
|
from importlib.resources import files
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
@ -43,20 +43,28 @@ class ISOCurrency:
|
||||||
|
|
||||||
|
|
||||||
def current_data_date():
|
def current_data_date():
|
||||||
one = etree.fromstring(read_binary("pricehist.resources", "list-one.xml"))
|
one = etree.fromstring(
|
||||||
|
files("pricehist.resources").joinpath("list-one.xml").read_bytes()
|
||||||
|
)
|
||||||
return one.cssselect("ISO_4217")[0].attrib["Pblshd"]
|
return one.cssselect("ISO_4217")[0].attrib["Pblshd"]
|
||||||
|
|
||||||
|
|
||||||
def historical_data_date():
|
def historical_data_date():
|
||||||
three = etree.fromstring(read_binary("pricehist.resources", "list-three.xml"))
|
three = etree.fromstring(
|
||||||
|
files("pricehist.resources").joinpath("list-three.xml").read_bytes()
|
||||||
|
)
|
||||||
return three.cssselect("ISO_4217")[0].attrib["Pblshd"]
|
return three.cssselect("ISO_4217")[0].attrib["Pblshd"]
|
||||||
|
|
||||||
|
|
||||||
def by_code():
|
def by_code():
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
one = etree.fromstring(read_binary("pricehist.resources", "list-one.xml"))
|
one = etree.fromstring(
|
||||||
three = etree.fromstring(read_binary("pricehist.resources", "list-three.xml"))
|
files("pricehist.resources").joinpath("list-one.xml").read_bytes()
|
||||||
|
)
|
||||||
|
three = etree.fromstring(
|
||||||
|
files("pricehist.resources").joinpath("list-three.xml").read_bytes()
|
||||||
|
)
|
||||||
|
|
||||||
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):
|
||||||
|
|
|
@ -42,7 +42,7 @@ import hashlib
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from importlib.resources import read_text
|
from importlib.resources import files
|
||||||
|
|
||||||
from pricehist import __version__
|
from pricehist import __version__
|
||||||
from pricehist.format import Format
|
from pricehist.format import Format
|
||||||
|
@ -119,13 +119,18 @@ class GnuCashSQL(BaseOutput):
|
||||||
"well."
|
"well."
|
||||||
)
|
)
|
||||||
|
|
||||||
sql = read_text("pricehist.resources", "gnucash.sql").format(
|
sql = (
|
||||||
version=__version__,
|
files("pricehist.resources")
|
||||||
timestamp=datetime.utcnow().isoformat() + "Z",
|
.joinpath("gnucash.sql")
|
||||||
base=self._sql_str(base),
|
.read_text()
|
||||||
quote=self._sql_str(quote),
|
.format(
|
||||||
values_comment=values_comment,
|
version=__version__,
|
||||||
values=values,
|
timestamp=datetime.utcnow().isoformat() + "Z",
|
||||||
|
base=self._sql_str(base),
|
||||||
|
quote=self._sql_str(quote),
|
||||||
|
values_comment=values_comment,
|
||||||
|
values=values,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return sql
|
return sql
|
||||||
|
|
Loading…
Add table
Reference in a new issue