From fed25c77f4ae953cee4a2a587a7176f7f9d2593c Mon Sep 17 00:00:00 2001 From: reimannsum Date: Sun, 12 Jun 2016 22:19:03 -0400 Subject: [PATCH 01/17] Improvements to HTML spoiler Changed how Creativity card examples are handled as to not flood magiccards.info and cause it to blacklist computer. Also added forum spoiler to each card. changed the link for similar cards to the magiccards.info page. --- decode.py | 10 +- lib/cardlib.py | 25 +- lib/html_extra_data.py | 820 +++++++++++++++++++++++------------------ 3 files changed, 478 insertions(+), 377 deletions(-) diff --git a/decode.py b/decode.py index 4f0bd19..f4373ac 100755 --- a/decode.py +++ b/decode.py @@ -69,9 +69,9 @@ def main(fname, oname = None, verbose = True, encoding = 'std', namestr = '' if for_html: if code: - namestr = ('
' + truename - + 'image' + ': ' + str(dist) + '
') + namestr = ('
' + ': ' + str(dist) + '
') else: namestr = '
' + truename + ': ' + str(dist) + '
' elif for_forum: @@ -111,10 +111,14 @@ def main(fname, oname = None, verbose = True, encoding = 'std', if creativity: cstring = '~~ closest cards ~~\n' + if for_html: + cstring += "
\n" nearest = card.nearest_cards for dist, cardname in nearest: cstring += hoverimg(cardname, dist, namediff) cstring += '~~ closest names ~~\n' + if for_html: + cstring += "
\n" nearest = card.nearest_names for dist, cardname in nearest: cstring += hoverimg(cardname, dist, namediff) diff --git a/lib/cardlib.py b/lib/cardlib.py index c655c17..5dc5a0c 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -651,6 +651,12 @@ class Card: rarity = self.__dict__[field_rarity] outstr += ' (' + rarity + ')' + if for_html and for_forum: + #force for_html to false to create tootip with forum spoiler + outstr += ('
[F]

' + + self.format(gatherer=gatherer, for_forum=for_forum, for_html=False, vdump=vdump).replace('\n', '
') + + '

') + if vdump: if not self.parsed: outstr += ' _UNPARSED_' @@ -736,6 +742,12 @@ class Card: outstr += ' _UNPARSED_' if not self.valid: outstr += ' _INVALID_' + + if for_html and for_forum: + #force for_html to false to create tootip with forum spoiler + outstr += ('
[F]

' + + self.format(gatherer=gatherer, for_forum=for_forum, for_html=False, vdump=vdump).replace('\n', '
') + + '

') outstr += linebreak @@ -810,13 +822,14 @@ class Card: outstr += linebreak outstr += self.bside.format(gatherer=gatherer, for_forum=for_forum, for_html=for_html, vdump=vdump) + # if for_html: + # if for_forum: + # outstr += linebreak + # # force for_html to false to create a copyable forum spoiler div + # outstr += ('
' + # + self.format(gatherer=gatherer, for_forum=for_forum, for_html=False, vdump=vdump).replace('\n', '
') + # + '
') if for_html: - if for_forum: - outstr += linebreak - # force for_html to false to create a copyable forum spoiler div - outstr += ('
' - + self.format(gatherer=gatherer, for_forum=for_forum, for_html=False, vdump=vdump).replace('\n', '
') - + '
') outstr += "" return outstr diff --git a/lib/html_extra_data.py b/lib/html_extra_data.py index db62a9d..60a3673 100644 --- a/lib/html_extra_data.py +++ b/lib/html_extra_data.py @@ -1,371 +1,455 @@ box_width = 350 html_prepend = """ - -""" + + + +""" From c24d2e31c271effb55ac2272438fec0b4f95d916 Mon Sep 17 00:00:00 2001 From: reimannsum Date: Mon, 13 Jun 2016 17:32:42 -0400 Subject: [PATCH 02/17] Fixed missing quotation mark --- decode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decode.py b/decode.py index f4373ac..f6fb249 100755 --- a/decode.py +++ b/decode.py @@ -69,7 +69,7 @@ def main(fname, oname = None, verbose = True, encoding = 'std', namestr = '' if for_html: if code: - namestr = ('
' + truename + 'image' + ': ' + str(dist) + '
') else: From fcba310d74fa14a719ab419a9b9601863cfa8ebc Mon Sep 17 00:00:00 2001 From: reimannsum Date: Mon, 13 Jun 2016 19:47:13 -0400 Subject: [PATCH 03/17] Fixed the things I broke missing styling moved from example files back to source code --- decode.py | 10 ++++++---- lib/cardlib.py | 4 ++-- lib/html_extra_data.py | 11 ++++------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/decode.py b/decode.py index f6fb249..cecce9d 100755 --- a/decode.py +++ b/decode.py @@ -69,9 +69,9 @@ def main(fname, oname = None, verbose = True, encoding = 'std', namestr = '' if for_html: if code: - namestr = ('
' + truename - + 'image' + ': ' + str(dist) + '
') + namestr = ('
' + truename + + '' + ': ' + str(dist) + '\n
\n') else: namestr = '
' + truename + ': ' + str(dist) + '
' elif for_forum: @@ -116,6 +116,8 @@ def main(fname, oname = None, verbose = True, encoding = 'std', nearest = card.nearest_cards for dist, cardname in nearest: cstring += hoverimg(cardname, dist, namediff) + if for_html: + cstring += "
\n" cstring += '~~ closest names ~~\n' if for_html: cstring += "
\n" @@ -123,7 +125,7 @@ def main(fname, oname = None, verbose = True, encoding = 'std', for dist, cardname in nearest: cstring += hoverimg(cardname, dist, namediff) if for_html: - cstring = '
' + cstring.replace('\n', '
\n') + '
\n' + cstring = '
' + cstring + '
\n' elif for_mse: cstring = ('\n\n' + cstring[:-1]).replace('\n', '\n\t\t') diff --git a/lib/cardlib.py b/lib/cardlib.py index 5dc5a0c..8a8b881 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -745,9 +745,9 @@ class Card: if for_html and for_forum: #force for_html to false to create tootip with forum spoiler - outstr += ('
[F]

' + outstr += ('

[F]

' + self.format(gatherer=gatherer, for_forum=for_forum, for_html=False, vdump=vdump).replace('\n', '
') - + '

') + + '

') outstr += linebreak diff --git a/lib/html_extra_data.py b/lib/html_extra_data.py index 60a3673..cb22334 100644 --- a/lib/html_extra_data.py +++ b/lib/html_extra_data.py @@ -11,8 +11,7 @@ html_prepend = """ } div.hover_img { position: relative; - left: 45%; - display:inline; + display:inline-block; } .hover_img a { position: relative; @@ -23,18 +22,16 @@ html_prepend = """ display: none; z-index: 99; } - .hover_img span:hover { - display:block; + .hover_img:hover span { + display:inline-block; } .hover_img span p { + padding: 10px; width:250px; background:#FFFF99; } - .hover_img a:hover span { - display: block; - } .hover_img img { height: 445px; width: 312px; From aeb2ff930c9b08857964f5ad071faf92db7cd6aa Mon Sep 17 00:00:00 2001 From: reimannsum Date: Mon, 13 Jun 2016 19:54:01 -0400 Subject: [PATCH 04/17] HTML override HTML flag now overrides and forces the forum stylings --- decode.py | 1 + 1 file changed, 1 insertion(+) diff --git a/decode.py b/decode.py index cecce9d..9f3a79d 100755 --- a/decode.py +++ b/decode.py @@ -88,6 +88,7 @@ def main(fname, oname = None, verbose = True, encoding = 'std', if for_html: # have to preapend html info writer.write(utils.html_prepend) + for_forum = True for card in cards: if for_mse: From 353910ef48e6229b62049a0ab84fe03fee43edeb Mon Sep 17 00:00:00 2001 From: reimannsum Date: Tue, 14 Jun 2016 13:16:01 -0400 Subject: [PATCH 05/17] add getter added getter function for field_cost.get_colors() also added code to add a "back to top" link to each card --- lib/cardlib.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/cardlib.py b/lib/cardlib.py index 8a8b881..c1836f8 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -747,7 +747,7 @@ class Card: #force for_html to false to create tootip with forum spoiler outstr += ('
[F]

' + self.format(gatherer=gatherer, for_forum=for_forum, for_html=False, vdump=vdump).replace('\n', '
') - + '

') + + '

back to top') outstr += linebreak @@ -1026,5 +1026,8 @@ class Card: return outstr + def get_colors(self): + return self.__dict__[field_cost].get_colors() + From b29e48dff5dd8c0aa89ad51c67a07d1c834e68db Mon Sep 17 00:00:00 2001 From: reimannsum Date: Tue, 14 Jun 2016 13:17:17 -0400 Subject: [PATCH 06/17] top nav labels added top nav and labels for sorting --- lib/html_extra_data.py | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/html_extra_data.py b/lib/html_extra_data.py index cb22334..cd3788d 100644 --- a/lib/html_extra_data.py +++ b/lib/html_extra_data.py @@ -1,7 +1,26 @@ box_width = 350 +id_lables = ["white", "blue", "black", "red", "green", "multi", "colorless"] html_prepend = """ -""" + + +""" From 7607a4d499902462dddac3f83dc0fcbab2230edd Mon Sep 17 00:00:00 2001 From: reimannsum Date: Tue, 14 Jun 2016 13:17:39 -0400 Subject: [PATCH 07/17] added sorting label support --- lib/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils.py b/lib/utils.py index 256896f..e15976b 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -11,6 +11,7 @@ mse_prepend = 'mse version: 0.3.8\ngame: magic\nstylesheet: m15\nset info:\n\tsy # special chunk of text to start an HTML document. import html_extra_data +segment_ids = html_extra_data.id_lables html_prepend = html_extra_data.html_prepend html_append = "\n\n" From 68b512a7e7faf378cd80fb8632d95a20d1c502ea Mon Sep 17 00:00:00 2001 From: reimannsum Date: Tue, 14 Jun 2016 13:21:19 -0400 Subject: [PATCH 08/17] added sorting sorting by color and color coded border boxes for each card. styling for --- decode.py | 87 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 16 deletions(-) diff --git a/decode.py b/decode.py index 9f3a79d..aa8e541 100755 --- a/decode.py +++ b/decode.py @@ -88,7 +88,18 @@ def main(fname, oname = None, verbose = True, encoding = 'std', if for_html: # have to preapend html info writer.write(utils.html_prepend) - for_forum = True + # seperate the write function to allow for writing smaller chunks of cards at a time + segments = sort_cards(cards) + for i in range(len(segments)): + # this allows card boxes to be colored for each color + # for coloring of each box seperately cardlib.Card.format() must change non-minimaly + writer.write('
') + writehtml(writer, segments[i]) + writer.write("
") + # closing the html file + writer.write(utils.html_append) + return #break out of the write cards funcrion to avoid writing cards twice + for card in cards: if for_mse: @@ -106,30 +117,19 @@ def main(fname, oname = None, verbose = True, encoding = 'std', else: fstring = card.format(gatherer = gatherer, for_forum = for_forum, vdump = vdump, for_html = for_html) - if creativity and for_html: - fstring = fstring[:-6] # chop off the closing to stick stuff in writer.write((fstring + '\n').encode('utf-8')) if creativity: cstring = '~~ closest cards ~~\n' - if for_html: - cstring += "
\n" nearest = card.nearest_cards for dist, cardname in nearest: cstring += hoverimg(cardname, dist, namediff) - if for_html: - cstring += "
\n" cstring += '~~ closest names ~~\n' - if for_html: - cstring += "
\n" nearest = card.nearest_names for dist, cardname in nearest: cstring += hoverimg(cardname, dist, namediff) - if for_html: - cstring = '
' + cstring + '
\n' - elif for_mse: + if for_mse: cstring = ('\n\n' + cstring[:-1]).replace('\n', '\n\t\t') - writer.write(cstring.encode('utf-8')) writer.write('\n'.encode('utf-8')) @@ -137,9 +137,64 @@ def main(fname, oname = None, verbose = True, encoding = 'std', if for_mse: # more formatting info writer.write('version control:\n\ttype: none\napprentice code: ') - if for_html: - # closing the html file - writer.write(utils.html_append) + + + def writehtml(writer, card_set): + for card in card_set: + fstring = card.format(gatherer = gatherer, for_forum = True, + vdump = vdump, for_html = for_html) + if creativity: + fstring = fstring[:-6] # chop off the closing to stick stuff in + writer.write((fstring + '\n').encode('utf-8')) + + if creativity: + cstring = '~~ closest cards ~~\n
\n' + nearest = card.nearest_cards + for dist, cardname in nearest: + cstring += hoverimg(cardname, dist, namediff) + cstring += "
\n" + cstring += '~~ closest names ~~\n
\n' + nearest = card.nearest_names + for dist, cardname in nearest: + cstring += hoverimg(cardname, dist, namediff) + cstring = '
' + cstring + '
\n' + writer.write(cstring.encode('utf-8')) + + writer.write('\n'.encode('utf-8')) + + def sort_cards(card_set): + # Initialize sections + red_cards = [] + blue_cards = [] + green_cards = [] + black_cards = [] + white_cards = [] + multi_cards = [] + colorless_cards = [] + for card in card_set: + if len(card.get_colors())>1: + multi_cards += [card] + continue + if 'R' in card.get_colors(): + red_cards += [card] + continue + elif 'U' in card.get_colors(): + blue_cards += [card] + continue + elif 'B' in card.get_colors(): + black_cards += [card] + continue + elif 'G' in card.get_colors(): + green_cards += [card] + continue + elif 'W' in card.get_colors(): + white_cards += [card] + continue + else: + colorless_cards += [card] + return[white_cards, blue_cards, black_cards, red_cards, green_cards, multi_cards, colorless_cards] + + if oname: if for_html: From 28c765719e28e487c9fc6c4acbae964a75a415dd Mon Sep 17 00:00:00 2001 From: reimannsum Date: Tue, 14 Jun 2016 13:43:33 -0400 Subject: [PATCH 09/17] updating gatherer output fixed outdated HTML code when using Gatherer flag --- lib/cardlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cardlib.py b/lib/cardlib.py index c1836f8..76f8759 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -655,7 +655,7 @@ class Card: #force for_html to false to create tootip with forum spoiler outstr += ('
[F]

' + self.format(gatherer=gatherer, for_forum=for_forum, for_html=False, vdump=vdump).replace('\n', '
') - + '

') + + '

back to top') if vdump: if not self.parsed: From adf0c1a44aa447c1d1a9d22518e06bf5a65f1423 Mon Sep 17 00:00:00 2001 From: reimannsum Date: Tue, 14 Jun 2016 13:57:23 -0400 Subject: [PATCH 10/17] Gatherer formatting in HTML moved the forum spoiler and 'back to top' in order to keep lines from spilling over. --- lib/cardlib.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/cardlib.py b/lib/cardlib.py index 76f8759..dd3718f 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -644,6 +644,13 @@ class Card: if vdump or not coststr == '_NOCOST_': outstr += ' ' + coststr + if for_html and for_forum: + #force for_html to false to create tootip with forum spoiler + outstr += ('
[F]

' + + self.format(gatherer=gatherer, for_forum=for_forum, for_html=False, vdump=vdump).replace('\n', '
') + + '

back to top') + + if self.__dict__[field_rarity]: if self.__dict__[field_rarity] in utils.json_rarity_unmap: rarity = utils.json_rarity_unmap[self.__dict__[field_rarity]] @@ -651,12 +658,7 @@ class Card: rarity = self.__dict__[field_rarity] outstr += ' (' + rarity + ')' - if for_html and for_forum: - #force for_html to false to create tootip with forum spoiler - outstr += ('
[F]

' - + self.format(gatherer=gatherer, for_forum=for_forum, for_html=False, vdump=vdump).replace('\n', '
') - + '

back to top') - + if vdump: if not self.parsed: outstr += ' _UNPARSED_' From 7056035719f1f2ea2747f96fd796b79711e9037f Mon Sep 17 00:00:00 2001 From: reimannsum Date: Tue, 14 Jun 2016 15:10:24 -0400 Subject: [PATCH 11/17] getters added getters for field_types and field_cost.cmc --- lib/cardlib.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/cardlib.py b/lib/cardlib.py index dd3718f..a5df0e3 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -1031,5 +1031,10 @@ class Card: def get_colors(self): return self.__dict__[field_cost].get_colors() + def get_types(self): + return self.__dict__[field_types] + + def get_cmc(self): + return self.__dict__[field_cost].cmc From 595d63649056ed64fc2492b561bc3bf776834f90 Mon Sep 17 00:00:00 2001 From: reimannsum Date: Tue, 14 Jun 2016 15:13:12 -0400 Subject: [PATCH 12/17] additional sorting added sorting out of lands and sorting each catagory by CMC --- decode.py | 27 ++++++++++++++++++++++++--- lib/html_extra_data.py | 6 +++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/decode.py b/decode.py index aa8e541..41b93cf 100755 --- a/decode.py +++ b/decode.py @@ -89,8 +89,10 @@ def main(fname, oname = None, verbose = True, encoding = 'std', # have to preapend html info writer.write(utils.html_prepend) # seperate the write function to allow for writing smaller chunks of cards at a time - segments = sort_cards(cards) + segments = sort_colors(cards) for i in range(len(segments)): + # sort color by CMC + segments[i] = sort_cmc(segments[i]) # this allows card boxes to be colored for each color # for coloring of each box seperately cardlib.Card.format() must change non-minimaly writer.write('
') @@ -162,7 +164,8 @@ def main(fname, oname = None, verbose = True, encoding = 'std', writer.write('\n'.encode('utf-8')) - def sort_cards(card_set): + # Sorting by colors + def sort_colors(card_set): # Initialize sections red_cards = [] blue_cards = [] @@ -171,6 +174,7 @@ def main(fname, oname = None, verbose = True, encoding = 'std', white_cards = [] multi_cards = [] colorless_cards = [] + lands = [] for card in card_set: if len(card.get_colors())>1: multi_cards += [card] @@ -191,9 +195,26 @@ def main(fname, oname = None, verbose = True, encoding = 'std', white_cards += [card] continue else: + if "land" in card.get_types(): + lands += [card] + continue colorless_cards += [card] - return[white_cards, blue_cards, black_cards, red_cards, green_cards, multi_cards, colorless_cards] + return[white_cards, blue_cards, black_cards, red_cards, green_cards, multi_cards, colorless_cards, lands] + def sort_cmc(card_set): + sorted_cards = [] + sorted_set = [] + for card in card_set: + # make sure there is an empty set for each CMC + while len(sorted_cards)-1 < card.get_cmc(): + sorted_cards += [] + # add card to correct set of CMC values + sorted_cards[card.get_cmc()] += [card] + # combine each set of CMC valued cards together + for value in sorted_cards: + for card in value: + sorted_set += [card] + return sorted_set if oname: diff --git a/lib/html_extra_data.py b/lib/html_extra_data.py index cd3788d..2d86303 100644 --- a/lib/html_extra_data.py +++ b/lib/html_extra_data.py @@ -1,5 +1,5 @@ box_width = 350 -id_lables = ["white", "blue", "black", "red", "green", "multi", "colorless"] +id_lables = ["white", "blue", "black", "red", "green", "multi", "colorless", "lands"] html_prepend = """