diff --git a/src/pricehist/isocurrencies.py b/src/pricehist/isocurrencies.py index bd453dc..624fe1d 100644 --- a/src/pricehist/isocurrencies.py +++ b/src/pricehist/isocurrencies.py @@ -24,7 +24,7 @@ Functions: """ from dataclasses import dataclass, field -from importlib.resources import read_binary +from importlib.resources import files from typing import List from lxml import etree @@ -43,20 +43,28 @@ class ISOCurrency: 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"] 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"] def by_code(): result = {} - one = etree.fromstring(read_binary("pricehist.resources", "list-one.xml")) - three = etree.fromstring(read_binary("pricehist.resources", "list-three.xml")) + one = etree.fromstring( + 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"): if currency := _parse(entry): diff --git a/src/pricehist/outputs/gnucashsql.py b/src/pricehist/outputs/gnucashsql.py index 723fcd4..44841c1 100644 --- a/src/pricehist/outputs/gnucashsql.py +++ b/src/pricehist/outputs/gnucashsql.py @@ -42,7 +42,7 @@ import hashlib import logging from datetime import datetime from decimal import Decimal -from importlib.resources import read_text +from importlib.resources import files from pricehist import __version__ from pricehist.format import Format @@ -119,13 +119,18 @@ class GnuCashSQL(BaseOutput): "well." ) - sql = read_text("pricehist.resources", "gnucash.sql").format( - version=__version__, - timestamp=datetime.utcnow().isoformat() + "Z", - base=self._sql_str(base), - quote=self._sql_str(quote), - values_comment=values_comment, - values=values, + sql = ( + files("pricehist.resources") + .joinpath("gnucash.sql") + .read_text() + .format( + version=__version__, + timestamp=datetime.utcnow().isoformat() + "Z", + base=self._sql_str(base), + quote=self._sql_str(quote), + values_comment=values_comment, + values=values, + ) ) return sql