diff --git a/lib/cardlib.py b/lib/cardlib.py index fdf04ed..391162c 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -11,7 +11,24 @@ from titlecase import titlecase except ImportError: def titlecase(s): - return s.title() + s = s.title() + smallwords = [ + "'S", + ' A ', + ' And ', + ' As ', + ' At ', + ' For ', + ' From ', + ' In ', + ' Of ', + ' The ', + ' To ', + ' With ', + ] + for word in smallwords: + s = s.replace(word, word.lower()) + return s try: import textwrap @@ -678,8 +695,9 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html = outstr += ' '.join(map(str.capitalize, self.__dict__[field_supertypes]) + basetypes) if self.__dict__[field_subtypes]: - outstr += (' ' + utils.dash_marker + ' ' + - ' '.join(self.__dict__[field_subtypes]).title()) + outstr += (' ' + utils.dash_marker) + for subtype in self.__dict__[field_subtypes]: + outstr += ' ' + titlecase(subtype) if self.__dict__[field_pt]: outstr += ' (' + utils.from_unary(self.__dict__[field_pt]) + ')' @@ -737,6 +755,10 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html = #cardname = transforms.name_unpass_1_dashes(self.__dict__[field_name]) if vdump and not cardname: cardname = '_NONAME_' + else: + cardname = titlecase(cardname) + if for_forum: + cardname = '[b]' + cardname + '[/b]' outstr += cardname coststr = self.__dict__[field_cost].format(for_forum=for_forum, for_html=for_html) @@ -757,9 +779,17 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html = outstr += linebreak - outstr += ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types]) + if self.__dict__[field_supertypes]: + for supertype in self.__dict__[field_supertypes]: + outstr += titlecase(supertype) + ' ' + for maintype in self.__dict__[field_types]: + outstr += titlecase(maintype) + ' ' if self.__dict__[field_subtypes]: - outstr += ' ' + utils.dash_marker + ' ' + ' '.join(self.__dict__[field_subtypes]) + outstr += utils.dash_marker + for subtype in self.__dict__[field_subtypes]: + outstr += ' ' + titlecase(subtype) + else: + outstr = outstr.strip() if self.__dict__[field_rarity]: if self.__dict__[field_rarity] in utils.json_rarity_unmap: @@ -777,6 +807,7 @@ def format(self, gatherer = False, for_forum = False, vdump = False, for_html = #mtext = transforms.text_unpass_3_uncast(mtext) mtext = transforms.text_unpass_4_unary(mtext) mtext = transforms.text_unpass_5_symbols(mtext, for_forum, for_html) + mtext = sentencecase(mtext) #mtext = transforms.text_unpass_6_cardname(mtext, cardname) mtext = transforms.text_unpass_7_newlines(mtext) #mtext = transforms.text_unpass_8_unicode(mtext) @@ -864,7 +895,10 @@ def to_mse(self, print_raw = False, vdump = False): outstr += '\tsuper type: ' + ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types]).title() + '\n' if self.__dict__[field_subtypes]: - outstr += '\tsub type: ' + ' '.join(self.__dict__[field_subtypes]).title() + '\n' + outstr += ('\tsub type:') + for subtype in self.__dict__[field_subtypes]: + outstr += ' ' + titlecase(subtype) + outstr += '\n' if self.__dict__[field_pt]: ptstring = utils.from_unary(self.__dict__[field_pt]).split('/') @@ -1040,5 +1074,3 @@ def get_types(self): def get_cmc(self): return self.__dict__[field_cost].cmc - -