diff --git a/README.md b/README.md index b7dbad7..02c5707 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,25 @@ # 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 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 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 diff --git a/source/mtga/set_data/dynamic.py b/source/mtga/set_data/dynamic.py index 13afa30..ebd7f35 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 @@ -12,11 +13,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") @@ -26,18 +24,38 @@ 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\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\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": ""}