From cc59c175ec9a5a02cac2460f6f44d0a5bf87f461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Sun, 3 Nov 2024 11:43:13 +0000 Subject: [PATCH] Add card type filter --- .gitignore | 1 + collectinggen.py | 45 +++++++++++++++++++++++++++++++++----- download.py | 2 +- generate.py | 6 ++--- ownedgen.py | 46 ++++++++++++++++++++++++++++++++------ tcgcore.py | 27 +++++++++++++---------- tradegen.py | 57 ++++++++++++++++++++++++++++++++++++++++-------- 7 files changed, 147 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 8857b56..0533bc7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +build/*/*/index.html build/*/index.html build/index.html build/decks/*/*.gif diff --git a/collectinggen.py b/collectinggen.py index a3530be..6d7746a 100644 --- a/collectinggen.py +++ b/collectinggen.py @@ -1,19 +1,28 @@ import datetime,os import log,variables,skel,tcgcore -def collectinggen(): +def collectinggen(colour=False): if not os.path.isdir("build/collecting"): os.mkdir("build/collecting") - if os.path.exists("build/collecting/index.html"): - os.remove("build/collecting/index.html") - thefile = "build/collecting/index.html" + if colour: + if not os.path.isdir("build/collecting/" + colour): + os.mkdir("build/collecting/" + colour) + thefile = "build/collecting/" + colour + "/index.html" + else: + thefile = "build/collecting/index.html" + if os.path.exists(thefile): + os.remove(thefile) skel.headerwrite(thefile,"collecting") content = open(thefile,"a") content.write("

decks in progress

\n") decksofinterest = [] for card in tcgcore.ownedcards(): if card[0:4] != "sig_": - decksofinterest.append(card[:-2]) + if colour: + if tcgcore.cardtype(card) == colour: + decksofinterest.append(card[:-2]) + else: + decksofinterest.append(card[:-2]) decksofinterest = sorted(list(dict.fromkeys(decksofinterest))) highpriority = [] medpriority = [] @@ -26,6 +35,25 @@ def collectinggen(): else: if tcgcore.collecting(deck): lowpriority.append(deck) + content.write("

") + if colour: + content.write("Filtered to ") + if colour == "gray": + if variables.british: + content.write("grey") + else: + content.write("gray") + else: + content.write(colour) + content.write(". Show all") + else: + content.write("Filter: 🔴 🟠 🟡 🟢 🔵 🟣 🟤 ") + content.write("

\n") if len(highpriority) > 0: content.write("
\n

High priority

\n") for deck in highpriority: @@ -44,5 +72,10 @@ def collectinggen(): content.close() skel.footerwrite(thefile) -if __name__ == "__main__": +def collectingall(): collectinggen() + for type in tcgcore.typelist: + collectinggen(type) + +if __name__ == "__main__": + collectingall() diff --git a/download.py b/download.py index 6084868..9790e80 100644 --- a/download.py +++ b/download.py @@ -14,7 +14,7 @@ def getimg(): index = 0 # adapted from https://stackoverflow.com/a/64536882 indexValidList = [] print("Deck type for " + card[:-2] + ":") - options = ["red","orange","yellow","green","blue","purple","brown","gray","special"] + options = tcgcore.typelist for optionName in options: index = index + 1 indexValidList.extend([options.index(optionName)]) diff --git a/generate.py b/generate.py index 141279d..d9f0e5c 100644 --- a/generate.py +++ b/generate.py @@ -2,9 +2,9 @@ import download,indexgen,collectinggen,ownedgen,wantedgen,loggen,levelsgen,trade download.getimg() indexgen.indexgen() -collectinggen.collectinggen() -ownedgen.ownedgen() +collectinggen.collectingall() +ownedgen.ownedall() wantedgen.wantedgen() loggen.loggen() levelsgen.levelsgen() -tradegen.tradegen() +tradegen.tradeall() diff --git a/ownedgen.py b/ownedgen.py index 25109d6..a77e5ef 100644 --- a/ownedgen.py +++ b/ownedgen.py @@ -1,21 +1,53 @@ import datetime,os -import log,skel,tcgcore +import log,skel,tcgcore,variables -def ownedgen(): +def ownedgen(colour=False): if not os.path.isdir("build/owned"): os.mkdir("build/owned") - if os.path.exists("build/owned/index.html"): - os.remove("build/owned/index.html") - thefile = "build/owned/index.html" + if colour: + if not os.path.isdir("build/owned/" + colour): + os.mkdir("build/owned/" + colour) + thefile = "build/owned/" + colour + "/index.html" + else: + thefile = "build/owned/index.html" + if os.path.exists(thefile): + os.remove(thefile) skel.headerwrite(thefile,"owned") content = open(thefile,"a") content.write("

owned cards

\n

") + if colour: + content.write("Filtered to ") + if colour == "gray": + if variables.british: + content.write("grey") + else: + content.write("gray") + else: + content.write(colour) + content.write(". Show all") + else: + content.write("Filter: 🔴 🟠 🟡 🟢 🔵 🟣 🟤 ") + content.write("

\n

") for card in tcgcore.ownedcards(): if card[0:4] != "sig_": - content.write(tcgcore.printcard(card)) + if colour: + if tcgcore.cardtype(card) == colour: + content.write(tcgcore.printcard(card)) + else: + content.write(tcgcore.printcard(card)) content.write("

\n") content.close() skel.footerwrite(thefile) -if __name__ == "__main__": +def ownedall(): ownedgen() + for type in tcgcore.typelist: + ownedgen(type) + +if __name__ == "__main__": + ownedall() diff --git a/tcgcore.py b/tcgcore.py index fc004d6..1c8eb21 100644 --- a/tcgcore.py +++ b/tcgcore.py @@ -1,5 +1,7 @@ import log,variables +typelist = ["red","orange","yellow","green","blue","purple","brown","gray","special"] + def ownedcards(): ownedcards = [] for event in log.log: @@ -35,35 +37,38 @@ def collecting(deck): else: return True +def cardtype(card): + with open("build/decks/" + card[:-2] + "/type") as thetype: + cardtype = thetype.read() + return(cardtype) + def cardtext(card): cardtext = "" if card[0:4] == "sig_": cardtext += "" + card + "" else: - with open("build/decks/" + card[:-2] + "/type") as thetype: - cardtype = thetype.read() - if cardtype == "red": + if cardtype(card) == "red": cardtext += "🔴" - elif cardtype == "orange": + elif cardtype(card) == "orange": cardtext += "🟠" - elif cardtype == "yellow": + elif cardtype(card) == "yellow": cardtext += "🟡" - elif cardtype == "green": + elif cardtype(card) == "green": cardtext += "🟢" - elif cardtype == "blue": + elif cardtype(card) == "blue": cardtext += "🔵" - elif cardtype == "purple": + elif cardtype(card) == "purple": cardtext += "🟣" - elif cardtype == "brown": + elif cardtype(card) == "brown": cardtext += "🟤" - elif cardtype == "gray": + elif cardtype(card) == "gray": cardtext += "" - elif cardtype == "special": + elif cardtype(card) == "special": cardtext += "" cardtext += card + "" return cardtext diff --git a/tradegen.py b/tradegen.py index c86ecac..6cbe77e 100644 --- a/tradegen.py +++ b/tradegen.py @@ -1,30 +1,69 @@ import datetime,os import log,skel,tcgcore,variables -def tradegen(): +def tradegen(colour=False): if not os.path.isdir("build/trade"): os.mkdir("build/trade") - if os.path.exists("build/trade/index.html"): - os.remove("build/trade/index.html") - thefile = "build/trade/index.html" + if colour: + if not os.path.isdir("build/trade/" + colour): + os.mkdir("build/trade/" + colour) + thefile = "build/trade/" + colour + "/index.html" + else: + thefile = "build/trade/index.html" + if os.path.exists(thefile): + os.remove(thefile) skel.headerwrite(thefile,"trade") content = open(thefile,"a") content.write("

available for trade

\n

") + if colour: + content.write("Filtered to ") + if colour == "gray": + if variables.british: + content.write("grey") + else: + content.write("gray") + else: + content.write(colour) + content.write(". Show all") + else: + content.write("Filter: 🔴 🟠 🟡 🟢 🔵 🟣 🟤 ") + content.write("

\n

") for card in tcgcore.ownedcards(): if card[0:4] != "sig_": - if not tcgcore.collecting(card[:-2]): - content.write(tcgcore.printcard(card)) + if colour: + if not tcgcore.collecting(card[:-2]): + if tcgcore.cardtype(card) == colour: + content.write(tcgcore.printcard(card)) + else: + if not tcgcore.collecting(card[:-2]): + content.write(tcgcore.printcard(card)) siglist = [] for card in tcgcore.ownedcards(): if card == "sig_" + variables.name.lower(): siglist.append(card) if variables.keepsig == True: siglist.remove(siglist[0]) - for sig in siglist: - content.write(tcgcore.printcard(sig)) + if colour: + if colour == "sig": + for sig in siglist: + content.write(tcgcore.printcard(sig)) + else: + for sig in siglist: + content.write(tcgcore.printcard(sig)) content.write("

\n

Trade cards here

\n") content.close() skel.footerwrite(thefile) -if __name__ == "__main__": +def tradeall(): tradegen() + for type in tcgcore.typelist: + tradegen(type) + tradegen("sig") + +if __name__ == "__main__": + tradeall()