Handle new edition print sheets properly

This commit is contained in:
friarsol
2020-12-03 22:32:45 -05:00
parent ce0875b8ce
commit b2b46176c7

View File

@@ -4,6 +4,7 @@
import json import json
import os,sys,fnmatch,re import os,sys,fnmatch,re
import requests import requests
import pdb
toolsDir = os.path.abspath(os.path.dirname( __file__ )) toolsDir = os.path.abspath(os.path.dirname( __file__ ))
resDir = os.path.abspath(os.path.join(toolsDir, '..', 'res')) resDir = os.path.abspath(os.path.join(toolsDir, '..', 'res'))
@@ -13,6 +14,8 @@ allJsonUrl = 'http://mtgjson.com/json/AllCards.json'
def initializeEditions(): def initializeEditions():
ignoredTypes = [ "From_the_Vault", "Duel_Decks", "Online", "Premium_Deck_Series" ] ignoredTypes = [ "From_the_Vault", "Duel_Decks", "Online", "Premium_Deck_Series" ]
editionSections = [ "[cards]", "[precon product]", "[borderless]", "[showcase]", "[extended art]", "[buy a box]", "[promo]" ]
print("Parsing Editions folder") print("Parsing Editions folder")
for root, dirnames, filenames in os.walk(editionsDir): for root, dirnames, filenames in os.walk(editionsDir):
for fileName in fnmatch.filter(filenames, '*.txt'): for fileName in fnmatch.filter(filenames, '*.txt'):
@@ -23,10 +26,11 @@ def initializeEditions():
metadata = True metadata = True
setcode = setname = settype = None setcode = setname = settype = None
for line in currentEdition.readlines(): for line in currentEdition.readlines():
line = line.strip()
if metadata: if metadata:
if line.startswith("[cards]"): if line in editionSections:
metadata = False metadata = False
if setcode: if setcode and setcode not in setCodes:
setCodes.append(setcode) setCodes.append(setcode)
setCodeToName[setcode] = setname setCodeToName[setcode] = setname
if settype in ignoredTypes: if settype in ignoredTypes:
@@ -42,24 +46,29 @@ def initializeEditions():
settype = line.split("=")[1].rstrip() settype = line.split("=")[1].rstrip()
else: else:
if line.startswith("[tokens]"): if not line:
# Hopefully tokens are last in the print sheet ordering
metadata = True
continue continue
if line.startswith("#") or line.startswith("["): if line.startswith("["):
if line not in editionSections:
metadata = True
continue continue
if line: if line.startswith("#"):
hasSetNumbers = line[0].isdigit() continue
card = line.split(" ", 2 if hasSetNumbers else 1)[-1].rstrip() hasSetNumbers = line[0].isdigit()
if card not in mtgDataCards: card = line.split(" ", 2 if hasSetNumbers else 1)[-1].rstrip().split('|')[0]
#print card
mtgDataCards[card] = [setcode]
else: if card.endswith('+'):
mtgDataCards[card].append(setcode) card = card[:-1]
if card not in mtgDataCards:
#print card
mtgDataCards[card] = [setcode]
else:
mtgDataCards[card].append(setcode)
print "Total Cards Found in all editions", len(mtgDataCards) print "Total Cards Found in all editions", len(mtgDataCards)
print "These sets will be ignored in some output files", ignoredSet print "These sets will be ignored in some output files", ignoredSet
@@ -90,7 +99,7 @@ def initializeOracleText():
return oracleDict return oracleDict
def normalizeOracle(oracle): def normalizeOracle(oracle):
return oracle.replace(u'\u2014', '-').replace(u'\u2212', '-').replace(u'\u2018', "'").replace(u'\u201c', '"').replace(u'\u201d', '"').replace(u'\u2022', '-').replace(u'\xc6', 'AE').replace(u'\xf6', 'o') return oracle.replace(u'\u2014', '-').replace(u'\u2212', '-').replace(u'\u2018', "'").replace(u'\u201c', '"').replace(u'\u201d', '"').replace(u'\u2022', '-').replace(u'\xc6', 'AE').replace(u'\xf6', 'o').replace(u'\xb2', '^2').replace(u'\xae', '(R)').replace(u'\u221e', 'INF')
def initializeForgeCards(): def initializeForgeCards():
@@ -347,7 +356,10 @@ if __name__ == '__main__':
except: except:
text = '' text = ''
output.write(text + '\n\n') try:
output.write(text + '\n\n')
except:
print everyMissing
output.write("\n") output.write("\n")
output.write("Total: " + str(total) + "\n") output.write("Total: " + str(total) + "\n")
output.write("Percentage implemented: " + str(round(percentage,2)) + "%\n") output.write("Percentage implemented: " + str(round(percentage,2)) + "%\n")