From 8f72ee5483fdab57ad2500b0a2cc1ca3078d34a9 Mon Sep 17 00:00:00 2001 From: Philip Kendall Date: Sat, 27 Jun 2020 20:47:05 +0100 Subject: [PATCH 1/4] Arena has gone 64-bit. Use the 64-bit registry and environment variables rather than the 32-bit versions when looking for the Arena data files. --- source/mtga/set_data/dynamic.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/source/mtga/set_data/dynamic.py b/source/mtga/set_data/dynamic.py index 13afa30..516f3e5 100644 --- a/source/mtga/set_data/dynamic.py +++ b/source/mtga/set_data/dynamic.py @@ -12,11 +12,8 @@ def _get_data_location_hardcoded(): root = os.environ.get( - "ProgramFiles(x86)", - os.environ.get( - "ProgramFiles", - r"C:\Program Files (x86)" - ) + "ProgramFiles", + r"C:\Program Files" ) return os.path.join(root, "Wizards of the Coast", "MTGA", "MTGA_Data", "Downloads", "Data") @@ -29,12 +26,12 @@ def _get_data_location_hardcoded(): try: from winreg import ConnectRegistry, OpenKey, HKEY_LOCAL_MACHINE, QueryValueEx registry_connection = ConnectRegistry(None, HKEY_LOCAL_MACHINE) - reg_path = r"SOFTWARE\WOW6432Node\Wizards of the Coast\MTGArena" + reg_path = r"SOFTWARE\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 @ ") print(data_location) - print(r"C:\Program Files (x86)\Wizards of the Coast\MTGA\MTGA_Data\Downloads\Data") + print(r"C:\Program Files\Wizards of the Coast\MTGA\MTGA_Data\Downloads\Data") except: print("Couldn't locate MTGA from registry, falling back to hardcoded path...") data_location = _get_data_location_hardcoded() From 8206a52000f946297b84738016685ce01fd9b20c Mon Sep 17 00:00:00 2001 From: Michele Gargiulo Date: Wed, 1 Jul 2020 20:09:38 +0200 Subject: [PATCH 2/4] Adds support for the new macOS MTGA client --- source/mtga/set_data/dynamic.py | 46 ++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/source/mtga/set_data/dynamic.py b/source/mtga/set_data/dynamic.py index 13afa30..bc0827f 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 +import sys from pathlib import Path from mtga.models.card import Card from mtga.models.card_set import Set @@ -26,18 +27,39 @@ def _get_data_location_hardcoded(): dynamic_set_tuples = [] -try: - from winreg import ConnectRegistry, OpenKey, HKEY_LOCAL_MACHINE, QueryValueEx - registry_connection = ConnectRegistry(None, HKEY_LOCAL_MACHINE) - 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 @ ") - print(data_location) - print(r"C:\Program Files (x86)\Wizards of the Coast\MTGA\MTGA_Data\Downloads\Data") -except: - print("Couldn't locate MTGA from registry, falling back to hardcoded path...") - data_location = _get_data_location_hardcoded() +def get_data_location(): + current_os = sys.platform + if current_os not in ["darwin", "win32"]: + raise + + return { + "darwin": get_darwin_data_location, + "win32": get_win_data_location, + }[current_os]() + +def get_darwin_data_location(): + return os.path.join( + os.path.expanduser("~"), + "Library/Application Support/com.wizards.mtga/Downloads/Data", + ) + +def get_win_data_location(): + try: + from winreg import ConnectRegistry, OpenKey, HKEY_LOCAL_MACHINE, QueryValueEx + registry_connection = ConnectRegistry(None, HKEY_LOCAL_MACHINE) + 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 @ ") + print(data_location) + print(r"C:\Program Files (x86)\Wizards of the Coast\MTGA\MTGA_Data\Downloads\Data") + except: + print("Couldn't locate MTGA from registry, falling back to hardcoded path...") + data_location = _get_data_location_hardcoded() + + return data_location + +data_location = get_data_location() json_filepaths = {"enums": "", "cards": "", "abilities": "", "loc": ""} From 3a480f288c1814d5fb275d97facefb0befd2432e Mon Sep 17 00:00:00 2001 From: Spencer Hawkins Date: Fri, 3 Jul 2020 14:40:06 -0700 Subject: [PATCH 3/4] Fix the readme for PyPI. Unbelievable. The LINE ENDINGS in the readme file is what has kept the readme blank this whole time. UN. BELIEVABLE. lol --- README.md | 23 +++++++++-------------- setup.py | 2 +- source/mtga/_version.py | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b7dbad7..f0f73c9 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,23 @@ # Python MTGA - -MTGA tools & set data for python. Generated with MTGJSON and scryfall, original MTGA grpId's -collected by Fugi & Spencatro. - +MTGA tools & set data for python. Original cardset generated with MTGJSON and scryfall, +with initial set of MTGA grpId's collected by Fugi & Spencatro. +(Now we just use the data already present in your MTGA installation.) ## Installation - `pip install mtga` - or - `python setup.py install` - ## Usage - ```python from mtga.set_data import all_mtga_cards -print(all_mtga_cards.find_one("63773")) -# +print(all_mtga_cards.find_one("Mangara")) +# +print(all_mtga_cards.find_one(71809)) +# +print(all_mtga_cards.find_one("71809")) +# ``` - ## Deploying - Because I always forget: - ```bash python setup.py sdist bdist_wheel twine upload dist/MTGA-* diff --git a/setup.py b/setup.py index fa0bc5a..d59eecd 100644 --- a/setup.py +++ b/setup.py @@ -76,7 +76,7 @@ def read_requirements_file(path): license="MIT License", # The project's main homepage. - url="https://github.com/mtgatracker/mtgatracker", + url="https://github.com/mtgatracker/python-mtga", # Author details author=__author__, diff --git a/source/mtga/_version.py b/source/mtga/_version.py index faa5dea..66c0415 100644 --- a/source/mtga/_version.py +++ b/source/mtga/_version.py @@ -1 +1 @@ -__version__ = "0.9.3" \ No newline at end of file +__version__ = "0.9.5" \ No newline at end of file From dc8e191445e93a3674d86bd09c0d5557a1568e4a Mon Sep 17 00:00:00 2001 From: Spencer Hawkins Date: Fri, 3 Jul 2020 14:56:44 -0700 Subject: [PATCH 4/4] Add reminder in readme to check line endings. BIG SIGH. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f0f73c9..02c5707 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,6 @@ print(all_mtga_cards.find_one("71809")) Because I always forget: ```bash python setup.py sdist bdist_wheel +twine check dist/* # check for readme issues (e.g. line endings MUST BE LF, not CRLF lol) twine upload dist/MTGA-* ``` \ No newline at end of file