From c5231ac9479f0e2d9d066b61257317e3ce9fd3a2 Mon Sep 17 00:00:00 2001 From: Bill Zorn Date: Fri, 17 Jul 2015 01:48:12 -0700 Subject: [PATCH] fixed a few little things --- decode.py | 5 +++-- lib/cardlib.py | 17 +++++++++++++++-- lib/utils.py | 16 +++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/decode.py b/decode.py index bb13992..56ca730 100755 --- a/decode.py +++ b/decode.py @@ -24,11 +24,11 @@ def main(fname, oname = None, verbose = True, gatherer = False, for_forum = Fals card = cardlib.Card(json_srcs[json_cardname][0]) if card.valid: valid += 1 - cards += [card] elif card.parsed: invalid += 1 else: unparsed += 1 + cards += [card] # fall back to opening a normal encoded file else: @@ -41,11 +41,12 @@ def main(fname, oname = None, verbose = True, gatherer = False, for_forum = Fals card = cardlib.Card(card_src) if card.valid: valid += 1 - cards += [card] elif card.parsed: invalid += 1 else: unparsed += 1 + cards += [card] + if verbose: print (str(valid) + ' valid, ' + str(invalid) + ' invalid, ' + str(unparsed) + ' failed to parse.') diff --git a/lib/cardlib.py b/lib/cardlib.py index decd016..cb31e6d 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -483,7 +483,12 @@ class Card: outstr += ' ' + self.__dict__[field_cost].format(for_forum = for_forum) if self.__dict__[field_rarity]: - outstr += '(' + self.__dict__[rarity] + ')' + outstr += ' (' + self.__dict__[rarity] + ')' + + if not self.parsed: + outstr += ' _UNPARSED_' + if not self.valid: + outstr += ' _INVALID_' outstr += '\n' @@ -533,7 +538,11 @@ class Card: cardname = self.__dict__[field_name] outstr += cardname if self.__dict__[field_rarity]: - outstr += '(' + self.__dict__[field_rarity] + ')' + outstr += ' (' + self.__dict__[field_rarity] + ')' + if not self.parsed: + outstr += ' _UNPARSED_' + if not self.valid: + outstr += ' _INVALID_' outstr += '\n' outstr += self.__dict__[field_cost].format(for_forum = for_forum) @@ -572,4 +581,8 @@ class Card: outstr += '<' + str(idx) + '> ' + str(value) outstr += '\n' + if self.bside: + outstr += utils.dash_marker * 8 + '\n' + outstr += self.bside.format(gatherer = gatherer, for_forum = for_forum) + return outstr diff --git a/lib/utils.py b/lib/utils.py index 8dc6438..ee4ae8c 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -441,22 +441,20 @@ symbol_regex = '[' + tap_marker + untap_marker + ']' def to_symbols(s): jsymstrs = re.findall(json_symbol_regex, s) - #for jsymstr in sorted(jsymstrs, lambda x,y: cmp(len(x), len(y)), reverse = True): - # See below. - for jsymstr in jsymstrs: - s = s.replace(jsymstr, json_symbol_trans[jsymstr], 1) + for jsymstr in sorted(jsymstrs, lambda x,y: cmp(len(x), len(y)), reverse = True): + s = s.replace(jsymstr, json_symbol_trans[jsymstr]) return s def from_symbols(s, for_forum = False): symstrs = re.findall(symbol_regex, s) #for symstr in sorted(symstrs, lambda x,y: cmp(len(x), len(y)), reverse = True): - # Since replacing doesn't remove the original match, have to do the right thing and go one - # at a time. We should probably use this method everywhere. - for symstr in symstrs: + # We have to do the right thing here, because the thing we replace exists in the thing + # we replace it with... + for symstr in set(symstrs): if for_forum: - s = s.replace(symstr, symbol_forum_trans[symstr], 1) + s = s.replace(symstr, symbol_forum_trans[symstr]) else: - s = s.replace(symstr, symbol_trans[symstr], 1) + s = s.replace(symstr, symbol_trans[symstr]) return s unletters_regex = r"[^abcdefghijklmnopqrstuvwxyz']"