Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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"))
# <Card: 'Torrential Gearhulk' ['Blue'] KLD 63773>
print(all_mtga_cards.find_one("Mangara"))
# <Card: 'Mangara, the Diplomat' ['White'] M21 71809>
print(all_mtga_cards.find_one(71809))
# <Card: 'Mangara, the Diplomat' ['White'] M21 71809>
print(all_mtga_cards.find_one("71809"))
# <Card: 'Mangara, the Diplomat' ['White'] M21 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-<version>*
```
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__,
Expand Down
2 changes: 1 addition & 1 deletion source/mtga/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.3"
__version__ = "0.9.5"
52 changes: 35 additions & 17 deletions source/mtga/set_data/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
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


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")

Expand All @@ -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": ""}

Expand Down