Add page for masteries, get deck types from a file, some refactoring

master
trémeur 3 weeks ago
parent 448b2187c6
commit 113461ce19

@ -28,6 +28,7 @@ def collectinggen(colour=False):
medpriority = [] medpriority = []
lowpriority = [] lowpriority = []
for deck in decksofinterest: for deck in decksofinterest:
if tcgcore.collecting(deck):
if deck in variables.highpriority: if deck in variables.highpriority:
highpriority.append(deck) highpriority.append(deck)
elif deck in variables.medpriority: elif deck in variables.medpriority:
@ -35,25 +36,7 @@ def collectinggen(colour=False):
else: else:
if tcgcore.collecting(deck): if tcgcore.collecting(deck):
lowpriority.append(deck) lowpriority.append(deck)
content.write("<p>") content.write(tcgcore.filterwrite("collecting",colour))
if colour:
content.write("Filtered to <b>")
if colour == "gray":
if variables.british:
content.write("grey")
else:
content.write("gray")
else:
content.write(colour)
content.write("</b>. <a href=\"/collecting\">Show all</a>")
else:
content.write("Filter: <a href=\"/collecting/red\" title=\"red\">🔴</a> <a href=\"/collecting/orange\" title=\"orange\">🟠</a> <a href=\"/collecting/yellow\" title=\"yellow\">🟡</a> <a href=\"/collecting/green\" title=\"green\">🟢</a> <a href=\"/collecting/blue\" title=\"blue\">🔵</a> <a href=\"/collecting/purple\" title=\"purple\">🟣</a> <a href=\"/collecting/brown\" title=\"brown\">🟤</a> <a href=\"/collecting/gray\" title=\"")
if variables.british:
content.write("grey")
else:
content.write("gray")
content.write("\">⚪</a> <a href=\"/collecting/special\" title=\"special\">✨</a>")
content.write("</p>\n")
if len(highpriority) > 0: if len(highpriority) > 0:
content.write("<div>\n<h2 class=\"collectingheader\">High priority</h2>\n") content.write("<div>\n<h2 class=\"collectingheader\">High priority</h2>\n")
for deck in highpriority: for deck in highpriority:

@ -1,5 +1,5 @@
import os,requests import os,requests
import tcgcore import tcgcore,thetypes
def getimg(): def getimg():
for card in tcgcore.ownedcards(): for card in tcgcore.ownedcards():
@ -11,6 +11,9 @@ def getimg():
thepath = "build/decks/" + card[:-2] thepath = "build/decks/" + card[:-2]
if not os.path.isdir(thepath): if not os.path.isdir(thepath):
os.mkdir(thepath) os.mkdir(thepath)
if card[:-2] in thetypes.typedict:
decktype = thetypes.typedict[card[:-2]]
else:
index = 0 # adapted from https://stackoverflow.com/a/64536882 index = 0 # adapted from https://stackoverflow.com/a/64536882
indexValidList = [] indexValidList = []
print("Deck type for " + card[:-2] + ":") print("Deck type for " + card[:-2] + ":")

@ -1,4 +1,4 @@
import download,indexgen,collectinggen,ownedgen,wantedgen,loggen,levelsgen,tradegen import download,indexgen,collectinggen,ownedgen,wantedgen,loggen,levelsgen,tradegen,masteredgen
download.getimg() download.getimg()
indexgen.indexgen() indexgen.indexgen()
@ -8,3 +8,4 @@ wantedgen.wantedgen()
loggen.loggen() loggen.loggen()
levelsgen.levelsgen() levelsgen.levelsgen()
tradegen.tradeall() tradegen.tradeall()
masteredgen.masteredall()

@ -0,0 +1,43 @@
import datetime,os
import log,variables,skel,tcgcore
def masteredgen(colour=False):
if not os.path.isdir("build/mastered"):
os.mkdir("build/mastered")
if colour:
if not os.path.isdir("build/mastered/" + colour):
os.mkdir("build/mastered/" + colour)
thefile = "build/mastered/" + colour + "/index.html"
else:
thefile = "build/mastered/index.html"
if os.path.exists(thefile):
os.remove(thefile)
skel.headerwrite(thefile,"mastered")
content = open(thefile,"a")
content.write("<h1>mastered decks</h1>\n")
decksofinterest = []
for card in tcgcore.ownedcards():
if card[0:4] != "sig_":
if colour:
if tcgcore.cardtype(card) == colour:
decksofinterest.append(card[:-2])
else:
decksofinterest.append(card[:-2])
decksofinterest = sorted(list(dict.fromkeys(decksofinterest)))
mastereddecks = []
for deck in decksofinterest:
if tcgcore.deckmastered(deck):
mastereddecks.append(deck)
content.write(tcgcore.filterwrite("mastered",colour))
for deck in mastereddecks:
content.write(tcgcore.printdeck(deck))
content.close()
skel.footerwrite(thefile)
def masteredall():
masteredgen()
for type in tcgcore.typelist:
masteredgen(type)
if __name__ == "__main__":
masteredall()

@ -14,25 +14,9 @@ def ownedgen(colour=False):
os.remove(thefile) os.remove(thefile)
skel.headerwrite(thefile,"owned") skel.headerwrite(thefile,"owned")
content = open(thefile,"a") content = open(thefile,"a")
content.write("<h1>owned cards</h1>\n<p>") content.write("<h1>owned cards</h1>\n")
if colour: content.write(tcgcore.filterwrite("owned",colour))
content.write("Filtered to <b>") content.write("<p>")
if colour == "gray":
if variables.british:
content.write("grey")
else:
content.write("gray")
else:
content.write(colour)
content.write("</b>. <a href=\"/owned\">Show all</a>")
else:
content.write("Filter: <a href=\"/owned/red\" title=\"red\">🔴</a> <a href=\"/owned/orange\" title=\"orange\">🟠</a> <a href=\"/owned/yellow\" title=\"yellow\">🟡</a> <a href=\"/owned/green\" title=\"green\">🟢</a> <a href=\"/owned/blue\" title=\"blue\">🔵</a> <a href=\"/owned/purple\" title=\"purple\">🟣</a> <a href=\"/owned/brown\" title=\"brown\">🟤</a> <a href=\"/owned/gray\" title=\"")
if variables.british:
content.write("grey")
else:
content.write("gray")
content.write("\">⚪</a> <a href=\"/owned/special\" title=\"special\">✨</a>")
content.write("</p>\n<p>")
for card in tcgcore.ownedcards(): for card in tcgcore.ownedcards():
if card[0:4] != "sig_": if card[0:4] != "sig_":
if colour: if colour:

@ -13,6 +13,11 @@ def headerwrite(thefile,pagename):
else: else:
header.write("<a href=\"/collecting\">collecting</a>") header.write("<a href=\"/collecting\">collecting</a>")
header.write("</li>\n <li>") header.write("</li>\n <li>")
if pagename == "mastered":
header.write("mastered")
else:
header.write("<a href=\"/mastered\">mastered</a>")
header.write("</li>\n <li>")
if pagename == "owned": if pagename == "owned":
header.write("owned") header.write("owned")
else: else:

@ -25,7 +25,14 @@ def deckcards(deck):
deckcards = sorted(list(dict.fromkeys(deckcards))) deckcards = sorted(list(dict.fromkeys(deckcards)))
return deckcards return deckcards
def deckmastered(deck):
if len(deckcards(deck)) == 20:
return True
else:
return False
def collecting(deck): def collecting(deck):
if len (deckcards(deck)) < 20:
if deck in variables.highpriority: if deck in variables.highpriority:
return True return True
else: else:
@ -36,6 +43,8 @@ def collecting(deck):
return False return False
else: else:
return True return True
else:
return False
def cardtype(card): def cardtype(card):
with open("build/decks/" + card[:-2] + "/type") as thetype: with open("build/decks/" + card[:-2] + "/type") as thetype:
@ -103,5 +112,31 @@ def printdeck(deck):
if test % 5 == 0: if test % 5 == 0:
deckstring += " </tr>\n" deckstring += " </tr>\n"
test += 1 test += 1
if deckmastered(deck):
deckstring += " <tr>\n <td colspan=\"5\" align=\"center\"><img src=\"/decks/" + deck + "/master.gif\" title=\"mastered " + deck + "\"><td>\n</tr>\n"
deckstring += "</tbody>\n</table>\n" deckstring += "</tbody>\n</table>\n"
return deckstring return deckstring
def filterwrite(page,colour=False,sigs=False):
filterstring = "<p class=\"typefilter\">"
if colour:
filterstring += "Filtered to <b>"
if colour == "gray":
if variables.british:
filterstring += "grey"
else:
filterstring += "gray"
else:
filterstring += colour
filterstring += "</b>. <a href=\"/" + page + "\">Show all</a>"
else:
filterstring += "Filter: <a href=\"/" + page + "/red\" title=\"red\">🔴</a> <a href=\"/" + page + "/orange\" title=\"orange\">🟠</a> <a href=\"/" + page + "/yellow\" title=\"yellow\">🟡</a> <a href=\"/" + page + "/green\" title=\"green\">🟢</a> <a href=\"/" + page + "/blue\" title=\"blue\">🔵</a> <a href=\"/" + page + "/purple\" title=\"purple\">🟣</a> <a href=\"/" + page + "/brown\" title=\"brown\">🟤</a> <a href=\"/" + page + "/gray\" title=\""
if variables.british:
filterstring += "grey"
else:
filterstring += "gray"
filterstring += "\">⚪</a> <a href=\"/" + page + "/special\" title=\"special\">✨</a>"
if sigs:
filterstring += " <a href=\"/" + page + "/sig\" title=\"sig\">✍</a>"
filterstring += "</p>\n"
return filterstring

File diff suppressed because it is too large Load Diff

@ -14,37 +14,29 @@ def tradegen(colour=False):
os.remove(thefile) os.remove(thefile)
skel.headerwrite(thefile,"trade") skel.headerwrite(thefile,"trade")
content = open(thefile,"a") content = open(thefile,"a")
content.write("<h1>available for trade</h1>\n<p>") content.write("<h1>available for trade</h1>\n")
if colour: content.write(tcgcore.filterwrite("trade",colour,True))
content.write("Filtered to <b>") content.write("<p>")
if colour == "gray":
if variables.british:
content.write("grey")
else:
content.write("gray")
else:
content.write(colour)
content.write("</b>. <a href=\"/trade\">Show all</a>")
else:
content.write("Filter: <a href=\"/trade/red\" title=\"red\">🔴</a> <a href=\"/trade/orange\" title=\"orange\">🟠</a> <a href=\"/trade/yellow\" title=\"yellow\">🟡</a> <a href=\"/trade/green\" title=\"green\">🟢</a> <a href=\"/trade/blue\" title=\"blue\">🔵</a> <a href=\"/trade/purple\" title=\"purple\">🟣</a> <a href=\"/trade/brown\" title=\"brown\">🟤</a> <a href=\"/trade/gray\" title=\"")
if variables.british:
content.write("grey")
else:
content.write("gray")
content.write("\">⚪</a> <a href=\"/trade/special\" title=\"special\">✨</a> <a href=\"/trade/sig\" title=\"sig\">✍</a>")
content.write("</p>\n<p>")
if len(variables.tradestatement) > 0: if len(variables.tradestatement) > 0:
content.write(variables.tradestatement + " ") content.write(variables.tradestatement + " ")
content.write("Trade cards <a href=\"" + variables.tradepost + "\">here</a></p>\n<p>") content.write("Trade cards <a href=\"" + variables.tradepost + "\">here</a></p>\n<p>")
previouscard = ""
for card in tcgcore.ownedcards(): for card in tcgcore.ownedcards():
if card[0:4] != "sig_": if card[0:4] != "sig_":
if card == previouscard:
if colour: if colour:
if not tcgcore.collecting(card[:-2]):
if tcgcore.cardtype(card) == colour: if tcgcore.cardtype(card) == colour:
content.write(tcgcore.printcard(card)) content.write(tcgcore.printcard(card))
else:
content.write(tcgcore.printcard(card))
else: else:
if not tcgcore.collecting(card[:-2]): if not tcgcore.collecting(card[:-2]):
if colour:
if tcgcore.cardtype(card) == colour:
content.write(tcgcore.printcard(card))
else:
content.write(tcgcore.printcard(card)) content.write(tcgcore.printcard(card))
previouscard = card
siglist = [] siglist = []
for card in tcgcore.ownedcards(): for card in tcgcore.ownedcards():
if card == "sig_" + variables.name.lower(): if card == "sig_" + variables.name.lower():

Loading…
Cancel
Save