some minor tweaks and improvements
This commit is contained in:
parent
6df5a4410e
commit
8cf4a7d955
2 changed files with 111 additions and 26 deletions
128
sortcards.py
128
sortcards.py
|
@ -1,41 +1,67 @@
|
||||||
import re
|
import re
|
||||||
import codecs
|
import codecs
|
||||||
import sys
|
import sys
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
# returns back a dictionary mapping the names of classes of cards
|
# returns back a dictionary mapping the names of classes of cards
|
||||||
# to lists of cards in those classes
|
# to lists of cards in those classes
|
||||||
def sortcards(cards):
|
def sortcards(cards):
|
||||||
classes = {
|
classes = OrderedDict([
|
||||||
'multicards' : [],
|
('Special classes:', None),
|
||||||
|
('multicards', []),
|
||||||
'X cards' : [],
|
('Inclusive classes:', None),
|
||||||
'counter cards' : [],
|
('X cards', []),
|
||||||
'choice cards' : [],
|
('kicker cards', []),
|
||||||
'equipment' : [],
|
('counter cards', []),
|
||||||
'levelers' : [],
|
('uncast cards', []),
|
||||||
'legendary' : [],
|
('choice cards', []),
|
||||||
|
('equipment', []),
|
||||||
'planeswalkers' : [],
|
('levelers', []),
|
||||||
'lands' : [],
|
('legendary', []),
|
||||||
'instants' : [],
|
('Exclusive classes:', None),
|
||||||
'sorceries' : [],
|
('planeswalkers', []),
|
||||||
'enchantments' : [],
|
('lands', []),
|
||||||
'noncreature artifacts' : [],
|
('instants', []),
|
||||||
'creatures' : [],
|
('sorceries', []),
|
||||||
'other' : [],
|
('enchantments', []),
|
||||||
}
|
('noncreature artifacts', []),
|
||||||
|
('creatures', []),
|
||||||
|
('other', []),
|
||||||
|
('By color:', None),
|
||||||
|
('white', []),
|
||||||
|
('blue', []),
|
||||||
|
('black', []),
|
||||||
|
('red', []),
|
||||||
|
('green', []),
|
||||||
|
('colorless nonland', []),
|
||||||
|
('colorless land', []),
|
||||||
|
('unknown color', []),
|
||||||
|
('By number of colors:', None),
|
||||||
|
('zero colors', []),
|
||||||
|
('one color', []),
|
||||||
|
('two colors', []),
|
||||||
|
('three colors', []),
|
||||||
|
('four colors', []),
|
||||||
|
('five colors', []),
|
||||||
|
('more colors?', []),
|
||||||
|
])
|
||||||
|
|
||||||
for card in cards:
|
for card in cards:
|
||||||
# special classes
|
# special classes
|
||||||
if '|\n|' in card:
|
if '|\n|' in card:
|
||||||
classes['multicards'] += [card]
|
# better formatting pls???
|
||||||
|
classes['multicards'] += [card.replace('|\n|', '|\n~~~~~~~~~~~~~~~~\n|')]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# inclusive classes
|
# inclusive classes
|
||||||
if 'X' in card:
|
if 'X' in card:
|
||||||
classes['X cards'] += [card]
|
classes['X cards'] += [card]
|
||||||
|
if 'kick' in card:
|
||||||
|
classes['kicker cards'] += [card]
|
||||||
if '#' in card:
|
if '#' in card:
|
||||||
classes['counter cards'] += [card]
|
classes['counter cards'] += [card]
|
||||||
|
if 'uncast' in card:
|
||||||
|
classes['uncast cards'] += [card]
|
||||||
if 'choose one ~' in card or 'choose two ~' in card or '=' in card:
|
if 'choose one ~' in card or 'choose two ~' in card or '=' in card:
|
||||||
classes['choice cards'] += [card]
|
classes['choice cards'] += [card]
|
||||||
if '|equipment|' in card or 'equip {' in card:
|
if '|equipment|' in card or 'equip {' in card:
|
||||||
|
@ -63,8 +89,56 @@ def sortcards(cards):
|
||||||
else:
|
else:
|
||||||
classes['other'] += [card]
|
classes['other'] += [card]
|
||||||
|
|
||||||
|
# color classes need to find the mana cost
|
||||||
|
fields = card.split('|')
|
||||||
|
if len(fields) != 10:
|
||||||
|
classes['unknown color'] += [card]
|
||||||
|
else:
|
||||||
|
cost = fields[7]
|
||||||
|
color_count = 0
|
||||||
|
if 'W' in cost or 'U' in cost or 'B' in cost or 'R' in cost or 'G' in cost:
|
||||||
|
if 'W' in cost:
|
||||||
|
classes['white'] += [card]
|
||||||
|
color_count += 1
|
||||||
|
if 'U' in cost:
|
||||||
|
classes['blue'] += [card]
|
||||||
|
color_count += 1
|
||||||
|
if 'B' in cost:
|
||||||
|
classes['black'] += [card]
|
||||||
|
color_count += 1
|
||||||
|
if 'R' in cost:
|
||||||
|
classes['red'] += [card]
|
||||||
|
color_count += 1
|
||||||
|
if 'G' in cost:
|
||||||
|
classes['green'] += [card]
|
||||||
|
color_count += 1
|
||||||
|
# should be unreachable
|
||||||
|
if color_count == 0:
|
||||||
|
classes['unknown color'] += [card]
|
||||||
|
else:
|
||||||
|
if '|land|' in card:
|
||||||
|
classes['colorless land'] += [card]
|
||||||
|
else:
|
||||||
|
classes['colorless nonland'] += [card]
|
||||||
|
|
||||||
|
if color_count == 0:
|
||||||
|
classes['zero colors'] += [card]
|
||||||
|
elif color_count == 1:
|
||||||
|
classes['one color'] += [card]
|
||||||
|
elif color_count == 2:
|
||||||
|
classes['two colors'] += [card]
|
||||||
|
elif color_count == 3:
|
||||||
|
classes['three colors'] += [card]
|
||||||
|
elif color_count == 4:
|
||||||
|
classes['four colors'] += [card]
|
||||||
|
elif color_count == 5:
|
||||||
|
classes['five colors'] += [card]
|
||||||
|
else:
|
||||||
|
classes['more colors?'] += [card]
|
||||||
|
|
||||||
return classes
|
return classes
|
||||||
|
|
||||||
|
|
||||||
def main(fname, oname = None, verbose = True):
|
def main(fname, oname = None, verbose = True):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Opening encoded card file: ' + fname
|
print 'Opening encoded card file: ' + fname
|
||||||
|
@ -83,7 +157,10 @@ def main(fname, oname = None, verbose = True):
|
||||||
ofile = codecs.open(oname, 'w', 'utf-8')
|
ofile = codecs.open(oname, 'w', 'utf-8')
|
||||||
|
|
||||||
for cardclass in classes:
|
for cardclass in classes:
|
||||||
print cardclass + ': ' + str(len(classes[cardclass]))
|
if classes[cardclass] == None:
|
||||||
|
print cardclass
|
||||||
|
else:
|
||||||
|
print ' ' + cardclass + ': ' + str(len(classes[cardclass]))
|
||||||
|
|
||||||
if oname == None:
|
if oname == None:
|
||||||
outputter = sys.stdout
|
outputter = sys.stdout
|
||||||
|
@ -91,10 +168,15 @@ def main(fname, oname = None, verbose = True):
|
||||||
outputter = ofile
|
outputter = ofile
|
||||||
|
|
||||||
for cardclass in classes:
|
for cardclass in classes:
|
||||||
outputter.write('[spoiler=' + cardclass + ']\n')
|
if classes[cardclass] == None:
|
||||||
|
outputter.write(cardclass + '\n')
|
||||||
|
else:
|
||||||
|
classlen = len(classes[cardclass])
|
||||||
|
if classlen > 0:
|
||||||
|
outputter.write('[spoiler=' + cardclass + ': ' + str(classlen) + ' cards]\n')
|
||||||
for card in classes[cardclass]:
|
for card in classes[cardclass]:
|
||||||
outputter.write(card + '\n\n')
|
outputter.write(card + '\n\n')
|
||||||
outputter.write('[/spoiler]')
|
outputter.write('[/spoiler]\n')
|
||||||
|
|
||||||
if not oname == None:
|
if not oname == None:
|
||||||
ofile.close()
|
ofile.close()
|
||||||
|
|
|
@ -93,7 +93,7 @@ def cleanup_mana(s, pretty = False):
|
||||||
innercost = innercost[2:]
|
innercost = innercost[2:]
|
||||||
|
|
||||||
if pretty:
|
if pretty:
|
||||||
cost = '[mana]' + cost + '[/mana]'
|
newcost = '[mana]' + newcost + '[/mana]'
|
||||||
|
|
||||||
if len(innercost) == 0 and success:
|
if len(innercost) == 0 and success:
|
||||||
s = s.replace(cost, newcost)
|
s = s.replace(cost, newcost)
|
||||||
|
@ -166,6 +166,9 @@ def main(fname, oname = None, verbose = True, pretty = False):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Opening encoded card file: ' + fname
|
print 'Opening encoded card file: ' + fname
|
||||||
|
|
||||||
|
if pretty:
|
||||||
|
print 'Using pretty [mana][/mana] encoding for mtgsalvation forum'
|
||||||
|
|
||||||
f = open(fname, 'r')
|
f = open(fname, 'r')
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
Loading…
Reference in a new issue