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
41
encode.py
41
encode.py
|
@ -468,36 +468,31 @@ def fix_x(s):
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# run after fixing dashes, it makes the regexes better, but before replacing newlines
|
# run after fixing dashes, it makes the regexes better, but before replacing newlines
|
||||||
def reformat_choice(s):
|
def reformat_choice(s):
|
||||||
# the idea is to take 'choose n ~\n=ability\n=ability\n'
|
# the idea is to take 'choose n ~\n=ability\n=ability\n'
|
||||||
# to '[n = ability = 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:
|
for choice in single_choices:
|
||||||
print choice
|
newchoice = choice[0]
|
||||||
print s
|
newchoice = newchoice.replace(prefix, unary_marker + (unary_counter * count))
|
||||||
# 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', ' ')
|
newchoice = newchoice.replace('\n', ' ')
|
||||||
# the indexing cuts off the | we know is at the end
|
if newchoice[-1:] == ' ':
|
||||||
newchoice = '[' + newchoice[:-1] + ']|'
|
newchoice = '[' + newchoice[:-1] + ']\n'
|
||||||
s = s.replace(choice, newchoice)
|
else:
|
||||||
|
newchoice = '[' + newchoice + ']'
|
||||||
|
s_helper = s_helper.replace(choice[0], newchoice)
|
||||||
|
return s_helper
|
||||||
|
|
||||||
# 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
|
return s
|
||||||
|
|
||||||
|
@ -563,7 +558,7 @@ def encode(card):
|
||||||
text = reformat_choice(text)
|
text = reformat_choice(text)
|
||||||
text = relocate_equip(text)
|
text = relocate_equip(text)
|
||||||
text = replace_newlines(text)
|
text = replace_newlines(text)
|
||||||
encoding += text
|
encoding += text.strip()
|
||||||
encoding += fieldsep
|
encoding += fieldsep
|
||||||
# if 'flavor' in card:
|
# if 'flavor' in card:
|
||||||
# encoding += card['flavor'].lower()
|
# 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