finished code for formatting choices, still need an unscrambler for it
This commit is contained in:
parent
bf6114c932
commit
b388ebc2e3
2 changed files with 2138 additions and 2143 deletions
45
encode.py
45
encode.py
|
@ -468,36 +468,31 @@ def fix_x(s):
|
|||
return s
|
||||
|
||||
|
||||
|
||||
|
||||
# run after fixing dashes, it makes the regexes better, but before replacing newlines
|
||||
def reformat_choice(s):
|
||||
# the idea is to take 'choose n ~\n=ability\n=ability\n'
|
||||
# to '[n = ability = ability]\n'
|
||||
|
||||
single_choices = re.findall(r'choose one', s)
|
||||
def choice_formatting_helper(s_helper, prefix, count):
|
||||
single_choices = re.findall(ur'(' + prefix + ur'\n?(\u2022.*(\n|$))+)', s_helper)
|
||||
for choice in single_choices:
|
||||
newchoice = choice[0]
|
||||
newchoice = newchoice.replace(prefix, unary_marker + (unary_counter * count))
|
||||
newchoice = newchoice.replace('\n', ' ')
|
||||
if newchoice[-1:] == ' ':
|
||||
newchoice = '[' + newchoice[:-1] + ']\n'
|
||||
else:
|
||||
newchoice = '[' + newchoice + ']'
|
||||
s_helper = s_helper.replace(choice[0], newchoice)
|
||||
return s_helper
|
||||
|
||||
for choice in single_choices:
|
||||
print choice
|
||||
print s
|
||||
# since we have two groups in that regex
|
||||
newchoice = choice
|
||||
# newchoice = newchoice.replace('choose one ~', unary_marker + (unary_counter * 1))
|
||||
# newchoice = newchoice.replace('\n', ' ')
|
||||
# # the indexing cuts off the | we know is at the end
|
||||
# newchoice = '[' + newchoice[:-1] + ']|'
|
||||
s = s.replace(choice, newchoice)
|
||||
|
||||
double_choices = re.findall(r'choose two ~[^|]*=[^\n|]*\|', s)
|
||||
|
||||
for choice in double_choices:
|
||||
# since we have two groups in that regex
|
||||
newchoice = choice
|
||||
newchoice = newchoice.replace('choose two ~', unary_marker + (unary_counter * 2))
|
||||
newchoice = newchoice.replace('\n', ' ')
|
||||
# the indexing cuts off the | we know is at the end
|
||||
newchoice = '[' + newchoice[:-1] + ']|'
|
||||
s = s.replace(choice, newchoice)
|
||||
|
||||
# sys.stdout.write('.')
|
||||
s = choice_formatting_helper(s, ur'choose one \u2014', 1)
|
||||
s = choice_formatting_helper(s, ur'choose one \u2014 ', 1) # ty Promise of Power
|
||||
s = choice_formatting_helper(s, ur'choose two \u2014', 2)
|
||||
s = choice_formatting_helper(s, ur'choose one or both \u2014', 0)
|
||||
s = choice_formatting_helper(s, ur'choose one or more \u2014', 0)
|
||||
|
||||
return s
|
||||
|
||||
|
@ -563,7 +558,7 @@ def encode(card):
|
|||
text = reformat_choice(text)
|
||||
text = relocate_equip(text)
|
||||
text = replace_newlines(text)
|
||||
encoding += text
|
||||
encoding += text.strip()
|
||||
encoding += fieldsep
|
||||
# if 'flavor' in card:
|
||||
# encoding += card['flavor'].lower()
|
||||
|
|
4232
output.txt
4232
output.txt
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue