Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for new MTG JSON #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
41 changes: 24 additions & 17 deletions lib/jdecode.py
Original file line number Diff line number Diff line change
@@ -3,11 +3,12 @@
import utils
import cardlib

def mtg_open_json(fname, verbose = False):

def mtg_open_json(fname, verbose=False):

with open(fname, 'r') as f:
jobj = json.load(f)
jobj = json.load(f)["data"]

allcards = {}
asides = {}
bsides = {}
@@ -19,7 +20,7 @@ def mtg_open_json(fname, verbose = False):
codename = set['magicCardsInfoCode']
else:
codename = ''

for card in set['cards']:
card[utils.json_field_set_name] = setname
card[utils.json_field_info_code] = codename
@@ -42,7 +43,7 @@ def mtg_open_json(fname, verbose = False):
allcards[cardname] += [card]
else:
allcards[cardname] = [card]

# also aggregate aside cards by uid so we can add bsides later
if uid[-1:] == 'a':
asides[uid] = card
@@ -59,29 +60,35 @@ def mtg_open_json(fname, verbose = False):
pass
# this exposes some coldsnap theme deck bsides that aren't
# really bsides; shouldn't matter too much
#print aside_uid
#print bsides[uid]
# print aside_uid
# print bsides[uid]

if verbose:
print 'Opened ' + str(len(allcards)) + ' uniquely named cards.'
return allcards

# filters to ignore some undesirable cards, only used when opening json


def default_exclude_sets(cardset):
return cardset == 'Unglued' or cardset == 'Unhinged' or cardset == 'Celebration'


def default_exclude_types(cardtype):
return cardtype in ['conspiracy']


def default_exclude_layouts(layout):
return layout in ['token', 'plane', 'scheme', 'phenomenon', 'vanguard']

# centralized logic for opening files of cards, either encoded or json
def mtg_open_file(fname, verbose = False,
linetrans = True, fmt_ordered = cardlib.fmt_ordered_default,
exclude_sets = default_exclude_sets,
exclude_types = default_exclude_types,
exclude_layouts = default_exclude_layouts):


def mtg_open_file(fname, verbose=False,
linetrans=True, fmt_ordered=cardlib.fmt_ordered_default,
exclude_sets=default_exclude_sets,
exclude_types=default_exclude_types,
exclude_layouts=default_exclude_layouts):

cards = []
valid = 0
@@ -116,7 +123,7 @@ def mtg_open_file(fname, verbose = False,

skip = False
if (exclude_sets(jcards[idx][utils.json_field_set_name])
or exclude_layouts(jcards[idx]['layout'])):
or exclude_layouts(jcards[idx]['layout'])):
skip = True
for cardtype in card.types:
if exclude_types(cardtype):
@@ -131,7 +138,7 @@ def mtg_open_file(fname, verbose = False,
elif card.parsed:
invalid += 1
if verbose:
print 'Invalid card: ' + json_cardname
print 'Invalid card: ' + json_cardname
else:
unparsed += 1

@@ -151,13 +158,13 @@ def mtg_open_file(fname, verbose = False,
elif card.parsed:
invalid += 1
if verbose:
print 'Invalid card: ' + json_cardname
print 'Invalid card: ' + json_cardname
else:
unparsed += 1

if verbose:
print (str(valid) + ' valid, ' + str(skipped) + ' skipped, '
+ str(invalid) + ' invalid, ' + str(unparsed) + ' failed to parse.')
print(str(valid) + ' valid, ' + str(skipped) + ' skipped, '
+ str(invalid) + ' invalid, ' + str(unparsed) + ' failed to parse.')

good_count = 0
bad_count = 0