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

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

@ -28,32 +28,15 @@ def collectinggen(colour=False):
medpriority = []
lowpriority = []
for deck in decksofinterest:
if deck in variables.highpriority:
highpriority.append(deck)
elif deck in variables.medpriority:
medpriority.append(deck)
else:
if tcgcore.collecting(deck):
lowpriority.append(deck)
content.write("<p>")
if colour:
content.write("Filtered to <b>")
if colour == "gray":
if variables.british:
content.write("grey")
if tcgcore.collecting(deck):
if deck in variables.highpriority:
highpriority.append(deck)
elif deck in variables.medpriority:
medpriority.append(deck)
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 tcgcore.collecting(deck):
lowpriority.append(deck)
content.write(tcgcore.filterwrite("collecting",colour))
if len(highpriority) > 0:
content.write("<div>\n<h2 class=\"collectingheader\">High priority</h2>\n")
for deck in highpriority:

@ -1,5 +1,5 @@
import os,requests
import tcgcore
import tcgcore,thetypes
def getimg():
for card in tcgcore.ownedcards():
@ -11,25 +11,28 @@ def getimg():
thepath = "build/decks/" + card[:-2]
if not os.path.isdir(thepath):
os.mkdir(thepath)
index = 0 # adapted from https://stackoverflow.com/a/64536882
indexValidList = []
print("Deck type for " + card[:-2] + ":")
options = tcgcore.typelist
for optionName in options:
index = index + 1
indexValidList.extend([options.index(optionName)])
print(str(index) + ") " + optionName)
inputValid = False
while not inputValid:
inputRaw = input("Type: ")
inputNo = int(inputRaw) - 1
if inputNo > -1 and inputNo < len(indexValidList):
selected = indexValidList[inputNo]
inputValid = True
break
else:
print("Select a number from the list")
decktype = options[selected]
if card[:-2] in thetypes.typedict:
decktype = thetypes.typedict[card[:-2]]
else:
index = 0 # adapted from https://stackoverflow.com/a/64536882
indexValidList = []
print("Deck type for " + card[:-2] + ":")
options = tcgcore.typelist
for optionName in options:
index = index + 1
indexValidList.extend([options.index(optionName)])
print(str(index) + ") " + optionName)
inputValid = False
while not inputValid:
inputRaw = input("Type: ")
inputNo = int(inputRaw) - 1
if inputNo > -1 and inputNo < len(indexValidList):
selected = indexValidList[inputNo]
inputValid = True
break
else:
print("Select a number from the list")
decktype = options[selected]
typefile = open(thepath + "/type","w")
typefile.write(decktype)
typefile.close()

@ -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()
indexgen.indexgen()
@ -8,3 +8,4 @@ wantedgen.wantedgen()
loggen.loggen()
levelsgen.levelsgen()
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)
skel.headerwrite(thefile,"owned")
content = open(thefile,"a")
content.write("<h1>owned cards</h1>\n<p>")
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=\"/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>")
content.write("<h1>owned cards</h1>\n")
content.write(tcgcore.filterwrite("owned",colour))
content.write("<p>")
for card in tcgcore.ownedcards():
if card[0:4] != "sig_":
if colour:

@ -13,6 +13,11 @@ def headerwrite(thefile,pagename):
else:
header.write("<a href=\"/collecting\">collecting</a>")
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":
header.write("owned")
else:

@ -25,17 +25,26 @@ def deckcards(deck):
deckcards = sorted(list(dict.fromkeys(deckcards)))
return deckcards
def collecting(deck):
if deck in variables.highpriority:
def deckmastered(deck):
if len(deckcards(deck)) == 20:
return True
else:
if deck in variables.medpriority:
return False
def collecting(deck):
if len (deckcards(deck)) < 20:
if deck in variables.highpriority:
return True
else:
if len(deckcards(deck)) < variables.collectthreshold:
return False
else:
if deck in variables.medpriority:
return True
else:
if len(deckcards(deck)) < variables.collectthreshold:
return False
else:
return True
else:
return False
def cardtype(card):
with open("build/decks/" + card[:-2] + "/type") as thetype:
@ -103,5 +112,31 @@ def printdeck(deck):
if test % 5 == 0:
deckstring += " </tr>\n"
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"
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)
skel.headerwrite(thefile,"trade")
content = open(thefile,"a")
content.write("<h1>available for trade</h1>\n<p>")
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=\"/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>")
content.write("<h1>available for trade</h1>\n")
content.write(tcgcore.filterwrite("trade",colour,True))
content.write("<p>")
if len(variables.tradestatement) > 0:
content.write(variables.tradestatement + " ")
content.write("Trade cards <a href=\"" + variables.tradepost + "\">here</a></p>\n<p>")
previouscard = ""
for card in tcgcore.ownedcards():
if card[0:4] != "sig_":
if colour:
if not tcgcore.collecting(card[:-2]):
if card == previouscard:
if colour:
if tcgcore.cardtype(card) == colour:
content.write(tcgcore.printcard(card))
else:
content.write(tcgcore.printcard(card))
else:
if not tcgcore.collecting(card[:-2]):
content.write(tcgcore.printcard(card))
if colour:
if tcgcore.cardtype(card) == colour:
content.write(tcgcore.printcard(card))
else:
content.write(tcgcore.printcard(card))
previouscard = card
siglist = []
for card in tcgcore.ownedcards():
if card == "sig_" + variables.name.lower():

Loading…
Cancel
Save