Add card search

master
trémeur 1 month ago
parent 6a21a3541a
commit af395bc486

@ -548,3 +548,13 @@ table.portfolio.gray td.deck7 {
table.portfolio.gray td.deck8 {
color: rgb(228,222,220);
}
/* card search */
form * {
display: block;
}
span.sorttitle {
font-weight: bold;
}

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

@ -0,0 +1,103 @@
import os
import skel,tcgcore,variables
def searchgen():
decksofinterest = []
for card in tcgcore.ownedcards():
if card[0:4] != "sig_":
decksofinterest.append(card[:-2])
decksofinterest = sorted(list(dict.fromkeys(decksofinterest)))
wantedcards = []
ownedcollecting = []
for deck in decksofinterest:
wantedlist = ["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20"]
for card in wantedlist:
combined = deck + card
if combined in tcgcore.ownedcards():
if tcgcore.collecting(deck):
ownedcollecting.append(combined)
else:
wantedcards.append(combined)
hpw = []
mpw = []
lpw = []
hpt = []
mpt = []
lpt = []
for card in wantedcards:
if card[:-2] in variables.highpriority:
hpw.append(card)
elif card[:-2] in variables.medpriority:
mpw.append(card)
else:
if tcgcore.collecting(card[:-2]):
lpw.append(card)
previouscard = ""
for card in tcgcore.ownedcards():
if card[0:4] != "sig_":
if card == previouscard:
lpt.append(card)
else:
if not tcgcore.deckmastered(card[:-2]):
if card in ownedcollecting:
if card[:-2] in variables.medpriority:
hpt.append(card)
else:
if card[:-2] not in variables.highpriority:
mpt.append(card)
else:
lpt.append(card)
if not os.path.isdir("build/search"):
os.mkdir("build/search")
thefile = "build/search/index.html"
if os.path.exists(thefile):
os.remove(thefile)
skel.headerwrite(thefile,"search")
content = open(thefile,"a")
content.write("<h1>card search</h1>\n<form>\n <label for=\"cardinput\">Paste a list of cards here:</label>\n <textarea id=\"cardinput\" name=\"cardinput\"></textarea>\n <input type=\"button\" value=\"Search\" onclick=\"searchcards()\">\n</form>\n<p id=\"hpwfound\"></p>\n<p id=\"mpwfound\"></p>\n<p id=\"lpwfound\"></p>\n<p id=\"hptfound\"></p>\n<p id=\"mptfound\"></p>\n<p id=\"lptfound\"></p>\n<p id=\"nothing\"></p>\n<script>\n function searchcards() {\n const hpw = [")
precomma = False
for card in hpw:
if precomma:
content.write(", ")
content.write("'" + card + "'")
precomma = True
content.write("];\n const mpw = [")
precomma = False
for card in mpw:
if precomma:
content.write(", ")
content.write("'" + card + "'")
precomma = True
content.write("];\n const lpw = [")
precomma = False
for card in lpw:
if precomma:
content.write(", ")
content.write("'" + card + "'")
precomma = True
content.write("];\n const hpt = [")
precomma = False
for card in hpt:
if precomma:
content.write(", ")
content.write("'" + card + "'")
precomma = True
content.write("];\n const mpt = [")
precomma = False
for card in mpt:
if precomma:
content.write(", ")
content.write("'" + card + "'")
precomma = True
content.write("];\n const lpt = [")
precomma = False
for card in lpt:
if precomma:
content.write(", ")
content.write("'" + card + "'")
precomma = True
content.write("];\n const searchstring = document.getElementById('cardinput').value;\n const searcharray = searchstring.replaceAll(' ','').split(',');\n const hpwfound = [];\n const mpwfound = [];\n const lpwfound = [];\n const hptfound = [];\n const mptfound = [];\n const lptfound = [];\n for (const element of searcharray) {\n if (hpw.includes(element)) {\n hpwfound.push(element);\n } else if (mpw.includes(element)) {\n mpwfound.push(element);\n } else if (lpw.includes(element)) {\n lpwfound.push(element);\n } else if (hpt.includes(element)) {\n hptfound.push(element);\n } else if (mpt.includes(element)) {\n mptfound.push(element);\n } else if (lpt.includes(element)) {\n lptfound.push(element);\n };\n };\n if ((hpwfound.length) > 0) {\n document.getElementById('hpwfound').innerHTML = '<span class=\"sorttitle\">Wanted (high priority):</span> ' + hpwfound.join(', ');\n } else {\n document.getElementById('hpwfound').innerHTML = '';\n };\n if ((mpwfound.length) > 0) {\n document.getElementById('mpwfound').innerHTML = '<span class=\"sorttitle\">Wanted (medium priority):</span> ' + mpwfound.join(', ');\n } else {\n document.getElementById('mpwfound').innerHTML = '';\n };\n if ((lpwfound.length) > 0) {\n document.getElementById('lpwfound').innerHTML = '<span class=\"sorttitle\">Wanted (low priority):</span> ' + lpwfound.join(', ');\n } else {\n document.getElementById('lpwfound').innerHTML = '';\n };\n if ((hptfound.length) > 0) {\n document.getElementById('hptfound').innerHTML = '<span class=\"sorttitle\">Will trade for <a href=\"/wanted\">high priority cards</a> only:</span> ' + hptfound.join(', ');\n } else {\n document.getElementById('hptfound').innerHTML = '';\n };\n if ((mptfound.length) > 0) {\n document.getElementById('mptfound').innerHTML = '<span class=\"sorttitle\">Will trade for <a href=\"/wanted\">high or medium priority cards</a>:</span> ' + mptfound.join(', ');\n } else {\n document.getElementById('mptfound').innerHTML = '';\n };\n if ((lptfound.length) > 0) {\n document.getElementById('lptfound').innerHTML = '<span class=\"sorttitle\">Will trade for <a href=\"/wanted\">any wanted card</a>:</span> ' + lptfound.join(', ');\n } else {\n document.getElementById('lptfound').innerHTML = '';\n };\n if ((hpwfound.length) + (mpwfound.length) + (lpwfound.length) + (hptfound.length) + (mptfound.length) + (lptfound.length) == 0) {\n document.getElementById('nothing').innerHTML = 'No results';\n } else {\n document.getElementById('nothing').innerHTML = '';\n }\n }\n</script>\n </main>\n </body>\n</html>")
content.close()
if __name__ == "__main__":
searchgen()

@ -33,6 +33,11 @@ def headerwrite(thefile,pagename):
else:
header.write("<a href=\"/wanted\">wanted</a>")
header.write("</li>\n <li>")
if pagename == "search":
header.write("search")
else:
header.write("<a href=\"/search\">search</a>")
header.write("</li>\n <li>")
if pagename == "log":
header.write("log")
else:

Loading…
Cancel
Save