From 4bd8b464d004dccbdd6952a8a6dd1ac9c48342ec Mon Sep 17 00:00:00 2001 From: Spencer Hawkins Date: Sun, 12 Apr 2020 21:28:49 -0700 Subject: [PATCH 1/6] bandaid: some ability ID's are failing to resolve --- source/mtga/set_data/dynamic.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/mtga/set_data/dynamic.py b/source/mtga/set_data/dynamic.py index 26fe688..668fedb 100644 --- a/source/mtga/set_data/dynamic.py +++ b/source/mtga/set_data/dynamic.py @@ -127,7 +127,12 @@ def _get_data_location_hardcoded(): for ability in abilities_raw: aid = ability["abilityId"] textid = ability["textId"] - text = loc_map[textid].encode("ascii", errors="ignore").decode() + try: + text = loc_map[textid].encode("ascii", errors="ignore").decode() + except: + # TODO: there are multiple loc files now?? something weird is up. I don't really feel like trying to + # figure this out right now though. + text = "unknown ability id {} / {}".format(aid, textid) abilities.append(aid) all_abilities[aid] = text @@ -140,7 +145,7 @@ def _get_data_location_hardcoded(): except Exception: print("hit an error on {} / {} / {}".format(card["grpid"], loc_map[card["titleId"]], card["CollectorNumber"])) - raise + # raise card_set_obj = Set(set_name_class_cased, cards=set_card_objs) dynamic_set_tuples.append((card_set_obj, all_abilities)) From e82fadca1e90721d30050e535da6bf16e40e461c Mon Sep 17 00:00:00 2001 From: Gene Cumm Date: Mon, 13 Apr 2020 16:46:16 -0400 Subject: [PATCH 2/6] set_data/dynamic.py: Make string literal Signed-off-by: Gene Cumm --- source/mtga/set_data/dynamic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/mtga/set_data/dynamic.py b/source/mtga/set_data/dynamic.py index 668fedb..e09ca89 100644 --- a/source/mtga/set_data/dynamic.py +++ b/source/mtga/set_data/dynamic.py @@ -28,7 +28,7 @@ def _get_data_location_hardcoded(): try: from winreg import ConnectRegistry, OpenKey, HKEY_LOCAL_MACHINE, QueryValueEx registry_connection = ConnectRegistry(None, HKEY_LOCAL_MACHINE) - reg_path = "SOFTWARE\WOW6432Node\Wizards of the Coast\MTGArena" + reg_path = r"SOFTWARE\WOW6432Node\Wizards of the Coast\MTGArena" registry_key = OpenKey(registry_connection, reg_path) data_location = QueryValueEx(registry_key, "Path")[0] + r"MTGA_Data\Downloads\Data" print("Found data @ ") From 0da01d7ae05ebff3d01db0ead724f5e30ce921af Mon Sep 17 00:00:00 2001 From: Gene Cumm Date: Mon, 13 Apr 2020 16:49:30 -0400 Subject: [PATCH 3/6] set_data/dynamic.py: Sort directory listing; deal with extra files Signed-off-by: Gene Cumm --- source/mtga/set_data/dynamic.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/mtga/set_data/dynamic.py b/source/mtga/set_data/dynamic.py index e09ca89..c168bde 100644 --- a/source/mtga/set_data/dynamic.py +++ b/source/mtga/set_data/dynamic.py @@ -5,6 +5,7 @@ import json import os import re +from pathlib import Path from mtga.models.card import Card from mtga.models.card_set import Set @@ -40,11 +41,19 @@ def _get_data_location_hardcoded(): json_filepaths = {"enums": "", "cards": "", "abilities": "", "loc": ""} -for filename in os.listdir(data_location): - key = filename.split("_")[1] +# A newer file SHOULD be the preference; alpha sort of hashes may be out of order +# Otherwise it will be necessary to find which is really used +for filepath in sorted(Path(data_location).iterdir(), key=os.path.getmtime): + filename = os.path.basename(filepath) + # In case of rogue files + filesplit = filename.split("_") + if len(filesplit) > 1: + key = filesplit[1] + else: + key = "" if key in json_filepaths.keys() and filename.endswith("mtga"): # print("setting {} to {}".format(key, filename)) - json_filepaths[key] = os.path.join(data_location, filename) + json_filepaths[key] = filepath with open(json_filepaths["cards"], "r", encoding="utf-8") as card_in: cards = json.load(card_in) From c4c57b24eba486b20c73434fd44d7c63d44ac4db Mon Sep 17 00:00:00 2001 From: Gene Cumm Date: Mon, 13 Apr 2020 16:51:10 -0400 Subject: [PATCH 4/6] set_data/dynamic.py: Deal with missing "CollectorNumber" Someone let a JSON out without this around 2020-04-10 Signed-off-by: Gene Cumm --- source/mtga/set_data/dynamic.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/mtga/set_data/dynamic.py b/source/mtga/set_data/dynamic.py index c168bde..a3cc7b9 100644 --- a/source/mtga/set_data/dynamic.py +++ b/source/mtga/set_data/dynamic.py @@ -124,10 +124,13 @@ def _get_data_location_hardcoded(): set_number = token_count + 10000 token_count += 1 else: - if card["CollectorNumber"].startswith("GR") or card["CollectorNumber"].startswith("GP"): - set_number = int(card["CollectorNumber"][2]) * 1000 - else: - set_number = int(card["CollectorNumber"]) + try: + if card["CollectorNumber"].startswith("GR") or card["CollectorNumber"].startswith("GP"): + set_number = int(card["CollectorNumber"][2]) * 1000 + else: + set_number = int(card["CollectorNumber"]) + except ValueError: + set_number = card["grpid"] grp_id = card["grpid"] abilities = [] From f60bd023d49a9e3eb601500f44840eac3af906a8 Mon Sep 17 00:00:00 2001 From: Gene Cumm Date: Mon, 13 Apr 2020 16:55:08 -0400 Subject: [PATCH 5/6] set_data/dynamic.py: Deal with missing isCollectible Someone let a JSON out without this around 2020-04-10 Signed-off-by: Gene Cumm --- source/mtga/set_data/dynamic.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/mtga/set_data/dynamic.py b/source/mtga/set_data/dynamic.py index a3cc7b9..13afa30 100644 --- a/source/mtga/set_data/dynamic.py +++ b/source/mtga/set_data/dynamic.py @@ -108,7 +108,10 @@ def _get_data_location_hardcoded(): # cc's look like: o2o(U/B)o(U/B)o3oUoB, want to turn it into ["2", "(U/B)"] etc cost = [cost_part for cost_part in cc_raw.split("o")[1:] if cost_part != "0"] color_identity = [COLOR_ID_MAP[color_id] for color_id in card["colorIdentity"]] - collectible = card["isCollectible"] + try: + collectible = card["isCollectible"] + except KeyError: + collectible = False card_type_ids = [enum_map["CardType"][card_type] for card_type in card["types"]] card_types = " ".join([loc_map[loc_id] for loc_id in card_type_ids]) From 6e185500df1d9e84c5c6501a6c6d27c71e599c3b Mon Sep 17 00:00:00 2001 From: Spencer Hawkins Date: Fri, 17 Apr 2020 17:41:15 -0700 Subject: [PATCH 6/6] bump version --- source/mtga/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/mtga/_version.py b/source/mtga/_version.py index d69d16e..faa5dea 100644 --- a/source/mtga/_version.py +++ b/source/mtga/_version.py @@ -1 +1 @@ -__version__ = "0.9.1" +__version__ = "0.9.3" \ No newline at end of file