mtgencode/scripts/randomize_mana.py
Bill Zorn 1a4965fd83 EVERYTHING HAS CHANGED
Added lib and script subdirs to organize things; the biggest change is that now
we have a really powerful Card class that can handle all of the decoding and
encoding for us. encode.py has been written to take advantage of this, other
things have not yet. Coming soon! As a side note the changes to output.txt
are purely cosemtic, though the order should be stable now.
2015-07-14 00:07:25 -07:00

46 lines
1.2 KiB
Python

import utils
import datamine
import random
def main(fname, oname = None, verbose = True):
if verbose:
print 'Opening encoded card file: ' + fname
with open(fname, 'rt') as f:
text = f.read()
cardtexts = text.split(utils.cardsep)
# overkill
datamine.analyze(cardtexts)
multicards = []
reps = 10
for card in datamine.cards:
for i in range(reps):
multicards += [card.reencode(randomize = True)]
# multicards += [card.reencode(randomize = True)
# + card.cost.reencode(randomize = True) + utils.fieldsep]
random.shuffle(multicards)
if oname:
if verbose:
print 'Writing output to: ' + oname
with open(oname, 'w') as ofile:
for textcard in multicards:
ofile.write(textcard + utils.cardsep)
else:
for textcard in multicards:
print textcard + '\n'
if __name__ == '__main__':
import sys
if len(sys.argv) == 2:
main(sys.argv[1])
elif len(sys.argv) == 3:
main(sys.argv[1], oname = sys.argv[2])
else:
print 'Usage: ' + sys.argv[0] + ' ' + '<encoded file> [output filename]'
exit(1)