From b63b950955c4567f6de0c13f20cb775c9bc987fe Mon Sep 17 00:00:00 2001 From: billzorn Date: Tue, 30 Jun 2015 23:02:48 -0700 Subject: [PATCH] sorting and unscrambling now handle new choice format --- sortcards.py | 4 ++-- unscramble.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sortcards.py b/sortcards.py index 60bb73e..515a3da 100644 --- a/sortcards.py +++ b/sortcards.py @@ -58,11 +58,11 @@ def sortcards(cards): classes['X cards'] += [card] if 'kick' in card: classes['kicker cards'] += [card] - if '#' in card: + if '%' in 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 '[' in card or ']' in card or '=' in card: classes['choice cards'] += [card] if '|equipment|' in card or 'equip {' in card: classes['equipment'] += [card] diff --git a/unscramble.py b/unscramble.py index daba284..58af564 100644 --- a/unscramble.py +++ b/unscramble.py @@ -108,6 +108,27 @@ def unreplace_newlines(s): return s.replace('\\', '\n') +def cleanup_choice(s): + openbrackets = re.findall(r'\[[0123456789]+', s) + for openbracket in openbrackets: + number = openbracket[1:] + i = int(number) + if i == 0: + s = s.replace(number, 'choose one or more ~') + elif i == 1: + s = s.replace(number, 'choose one ~') + elif i == 2: + s = s.replace(number, 'choose two ~') + else: + s = s.replace(number, 'choose ' + number + ' ~') + + clauses = re.findall(r'\[choose.*\]', s) + for clause in clauses: + newclause = clause.replace('=', '\n=') + s = s.replace(clause, newclause) + + return s + def forum_reorder(s): fields = s.split('|') # should see ten of em @@ -156,6 +177,7 @@ def forum_reorder(s): def unscramble(s, pretty = False): s = from_unary(s) + s = cleanup_choice(s) s = cleanup_mana(s, pretty) s = unreplace_newlines(s) s = forum_reorder(s)