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])
|
card = cardlib.Card(json_srcs[json_cardname][0])
|
||||||
if card.valid:
|
if card.valid:
|
||||||
valid += 1
|
valid += 1
|
||||||
cards += [card]
|
|
||||||
elif card.parsed:
|
elif card.parsed:
|
||||||
invalid += 1
|
invalid += 1
|
||||||
else:
|
else:
|
||||||
unparsed += 1
|
unparsed += 1
|
||||||
|
cards += [card]
|
||||||
|
|
||||||
# fall back to opening a normal encoded file
|
# fall back to opening a normal encoded file
|
||||||
else:
|
else:
|
||||||
|
@ -41,11 +41,12 @@ def main(fname, oname = None, verbose = True, gatherer = False, for_forum = Fals
|
||||||
card = cardlib.Card(card_src)
|
card = cardlib.Card(card_src)
|
||||||
if card.valid:
|
if card.valid:
|
||||||
valid += 1
|
valid += 1
|
||||||
cards += [card]
|
|
||||||
elif card.parsed:
|
elif card.parsed:
|
||||||
invalid += 1
|
invalid += 1
|
||||||
else:
|
else:
|
||||||
unparsed += 1
|
unparsed += 1
|
||||||
|
cards += [card]
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print (str(valid) + ' valid, ' + str(invalid) + ' invalid, '
|
print (str(valid) + ' valid, ' + str(invalid) + ' invalid, '
|
||||||
+ str(unparsed) + ' failed to parse.')
|
+ str(unparsed) + ' failed to parse.')
|
||||||
|
|
|
@ -485,6 +485,11 @@ class Card:
|
||||||
if self.__dict__[field_rarity]:
|
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'
|
outstr += '\n'
|
||||||
|
|
||||||
outstr += ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types]).title()
|
outstr += ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types]).title()
|
||||||
|
@ -534,6 +539,10 @@ class Card:
|
||||||
outstr += cardname
|
outstr += cardname
|
||||||
if self.__dict__[field_rarity]:
|
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 += '\n'
|
||||||
|
|
||||||
outstr += self.__dict__[field_cost].format(for_forum = for_forum)
|
outstr += self.__dict__[field_cost].format(for_forum = for_forum)
|
||||||
|
@ -572,4 +581,8 @@ class Card:
|
||||||
outstr += '<' + str(idx) + '> ' + str(value)
|
outstr += '<' + str(idx) + '> ' + str(value)
|
||||||
outstr += '\n'
|
outstr += '\n'
|
||||||
|
|
||||||
|
if self.bside:
|
||||||
|
outstr += utils.dash_marker * 8 + '\n'
|
||||||
|
outstr += self.bside.format(gatherer = gatherer, for_forum = for_forum)
|
||||||
|
|
||||||
return outstr
|
return outstr
|
||||||
|
|
16
lib/utils.py
16
lib/utils.py
|
@ -441,22 +441,20 @@ symbol_regex = '[' + tap_marker + untap_marker + ']'
|
||||||
|
|
||||||
def to_symbols(s):
|
def to_symbols(s):
|
||||||
jsymstrs = re.findall(json_symbol_regex, s)
|
jsymstrs = re.findall(json_symbol_regex, s)
|
||||||
#for jsymstr in sorted(jsymstrs, lambda x,y: cmp(len(x), len(y)), reverse = True):
|
for jsymstr in sorted(jsymstrs, lambda x,y: cmp(len(x), len(y)), reverse = True):
|
||||||
# See below.
|
s = s.replace(jsymstr, json_symbol_trans[jsymstr])
|
||||||
for jsymstr in jsymstrs:
|
|
||||||
s = s.replace(jsymstr, json_symbol_trans[jsymstr], 1)
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def from_symbols(s, for_forum = False):
|
def from_symbols(s, for_forum = False):
|
||||||
symstrs = re.findall(symbol_regex, s)
|
symstrs = re.findall(symbol_regex, s)
|
||||||
#for symstr in sorted(symstrs, lambda x,y: cmp(len(x), len(y)), reverse = True):
|
#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
|
# We have to do the right thing here, because the thing we replace exists in the thing
|
||||||
# at a time. We should probably use this method everywhere.
|
# we replace it with...
|
||||||
for symstr in symstrs:
|
for symstr in set(symstrs):
|
||||||
if for_forum:
|
if for_forum:
|
||||||
s = s.replace(symstr, symbol_forum_trans[symstr], 1)
|
s = s.replace(symstr, symbol_forum_trans[symstr])
|
||||||
else:
|
else:
|
||||||
s = s.replace(symstr, symbol_trans[symstr], 1)
|
s = s.replace(symstr, symbol_trans[symstr])
|
||||||
return s
|
return s
|
||||||
|
|
||||||
unletters_regex = r"[^abcdefghijklmnopqrstuvwxyz']"
|
unletters_regex = r"[^abcdefghijklmnopqrstuvwxyz']"
|
||||||
|
|
Loading…
Reference in a new issue