fixed a few little things
This commit is contained in:
parent
747614e355
commit
c5231ac947
3 changed files with 25 additions and 13 deletions
|
@ -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.')
|
||||
|
|
|
@ -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
|
||||
|
|
16
lib/utils.py
16
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']"
|
||||
|
|
Loading…
Reference in a new issue