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
49
encode.py
49
encode.py
|
@ -468,37 +468,32 @@ 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)
|
|
||||||
|
|
||||||
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:
|
def choice_formatting_helper(s_helper, prefix, count):
|
||||||
# since we have two groups in that regex
|
single_choices = re.findall(ur'(' + prefix + ur'\n?(\u2022.*(\n|$))+)', s_helper)
|
||||||
newchoice = choice
|
for choice in single_choices:
|
||||||
newchoice = newchoice.replace('choose two ~', unary_marker + (unary_counter * 2))
|
newchoice = choice[0]
|
||||||
newchoice = newchoice.replace('\n', ' ')
|
newchoice = newchoice.replace(prefix, unary_marker + (unary_counter * count))
|
||||||
# the indexing cuts off the | we know is at the end
|
newchoice = newchoice.replace('\n', ' ')
|
||||||
newchoice = '[' + newchoice[:-1] + ']|'
|
if newchoice[-1:] == ' ':
|
||||||
s = s.replace(choice, newchoice)
|
newchoice = '[' + newchoice[:-1] + ']\n'
|
||||||
|
else:
|
||||||
|
newchoice = '[' + newchoice + ']'
|
||||||
|
s_helper = s_helper.replace(choice[0], newchoice)
|
||||||
|
return s_helper
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
# sys.stdout.write('.')
|
|
||||||
|
|
||||||
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()
|
||||||
|
@ -573,7 +568,7 @@ def encode(card):
|
||||||
if 'bside' in card:
|
if 'bside' in card:
|
||||||
encoding += bsidesep
|
encoding += bsidesep
|
||||||
encoding += encode(card['bside'])
|
encoding += encode(card['bside'])
|
||||||
|
|
||||||
encoding = to_ascii(encoding)
|
encoding = to_ascii(encoding)
|
||||||
# encoding = re.sub(valid_encoded_char, '', encoding)
|
# encoding = re.sub(valid_encoded_char, '', encoding)
|
||||||
# if not encoding == '':
|
# if not encoding == '':
|
||||||
|
|
4232
output.txt
4232
output.txt
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue