Skip to content

Commit

Permalink
fix: add missing MercenariesXML url override
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Apr 17, 2024
1 parent a2267bc commit fc1bd72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions hearthstone/cardxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ def is_functional_duplicate_of(self, other):
XML_URL = "https://api.hearthstonejson.com/v1/latest/CardDefs.xml"


def _bootstrap_from_web(url: str, parse: Callable[[Iterator[Tuple[str, Any]]], None]):
def _bootstrap_from_web(parse: Callable[[Iterator[Tuple[str, Any]]], None], url=None):
if url is None:
url = XML_URL

with tempfile.TemporaryFile(mode="rb+") as fp:
if download_to_tempfile_retry(url, fp):
fp.flush()
Expand Down Expand Up @@ -446,7 +449,7 @@ def parse(context: Iterator[Tuple[str, Any]]):
has_lib = False

if not has_lib:
_bootstrap_from_web(url or XML_URL, parse)
_bootstrap_from_web(parse, url=url)

if not db:
_bootstrap_from_library(parse, path=path)
Expand Down
11 changes: 7 additions & 4 deletions hearthstone/mercenaryxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,12 @@ def to_xml(self):
XML_URL = "https://api.hearthstonejson.com/v1/latest/MercenaryDefs.xml"


def _bootstrap_from_web(parse: Callable[[Iterator[Tuple[str, Any]]], None]):
def _bootstrap_from_web(parse: Callable[[Iterator[Tuple[str, Any]]], None], url=None):
if url is None:
url = XML_URL

with tempfile.TemporaryFile(mode="rb+") as fp:
if download_to_tempfile_retry(XML_URL, fp):
if download_to_tempfile_retry(url, fp):
fp.flush()
fp.seek(0)

Expand All @@ -210,7 +213,7 @@ def _bootstrap_from_library(parse: Callable[[Iterator[Tuple[str, Any]]], None],
parse(ElementTree.iterparse(f, events=("start", "end",)))


def load(path=None, locale="enUS"):
def load(locale="enUS", path=None, url=None):
cache_key = (path, locale)
if cache_key not in mercenary_cache:
db = {}
Expand All @@ -232,7 +235,7 @@ def parse(context: Iterator[Tuple[str, Any]]):
root.clear() # type: ignore

if path is None:
_bootstrap_from_web(parse)
_bootstrap_from_web(parse, url=url)

if not db:
_bootstrap_from_library(parse, path=path)
Expand Down

0 comments on commit fc1bd72

Please sign in to comment.