You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
8.0 KiB
Python

2 months ago
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:
if tcgcore.collecting(deck):
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():
2 months ago
ownedcollecting.append(combined)
else:
wantedcards.append(combined)
2 months ago
hpw = []
mpw = []
lpw = []
hpt = []
mpt = []
lpt = []
for card in wantedcards:
if tcgcore.priority(card[:-2]) == "high":
2 months ago
hpw.append(card)
elif tcgcore.priority(card[:-2]) == "medium":
2 months ago
mpw.append(card)
elif tcgcore.priority(card[:-2]) == "low":
lpw.append(card)
2 months ago
previouscard = ""
for card in tcgcore.ownedcards():
if card[0:4] != "sig_":
if card == previouscard:
lpt.append(card)
else:
if not tcgcore.deckmastered(card[:-2]):
mass = False
for series in variables.masscollect:
try:
if card in variables.masscollect[series]["singles"]:
mass = True
except:
pass
if mass == True:
if tcgcore.priority(card[:-2]) != "high":
2 months ago
hpt.append(card)
else:
if card in ownedcollecting:
if tcgcore.priority(card[:-2]) == "medium":
hpt.append(card)
elif tcgcore.priority(card[:-2]) == "low":
mpt.append(card)
else:
lpt.append(card)
previouscard = card
hpw = sorted(list(dict.fromkeys(hpw)))
mpw = sorted(list(dict.fromkeys(mpw)))
lpw = sorted(list(dict.fromkeys(lpw)))
hpt = sorted(list(dict.fromkeys(hpt)))
mpt = sorted(list(dict.fromkeys(mpt)))
lpt = sorted(list(dict.fromkeys(lpt)))
2 months ago
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\">Enter a list of cards and/or decks 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 thecards = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'];\n const hpw = [")
2 months ago
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(' ','').replaceAll('\\n',',').replaceAll('\\r',',').toLowerCase().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 let cardend = element.substring(element.length, element.length - 2);\n if (!(thecards.includes(cardend))) {\n for (const ending of thecards) {\n searcharray.push(element + ending);\n };\n };\n };\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> <span class=\"searchresults\">' + hpwfound.join(', ') + '</span>';\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> <span class=\"searchresults\">' + mpwfound.join(', ') + '</span>';\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> <span class=\"searchresults\">' + lpwfound.join(', ') + '</span>';\n } else {\n document.getElementById('lpwfound').innerHTML = '';\n };\n if ((hptfound.length) > 0) {\n document.getElementById('hptfound').innerHTML = '<span class=\"sorttitle\">Will trade out for <a href=\"/wanted\">high priority cards</a> only:</span> <span class=\"searchresults\">' + hptfound.join(', ') + '</span>';\n } else {\n document.getElementById('hptfound').innerHTML = '';\n };\n if ((mptfound.length) > 0) {\n document.getElementById('mptfound').innerHTML = '<span class=\"sorttitle\">Will trade out for <a href=\"/wanted\">high or medium priority cards</a>:</span> <span class=\"searchresults\">' + mptfound.join(', ') + '</span>';\n } else {\n document.getElementById('mptfound').innerHTML = '';\n };\n if ((lptfound.length) > 0) {\n document.getElementById('lptfound').innerHTML = '<span class=\"sorttitle\">Will trade out for <a href=\"/wanted\">any wanted card</a>:</span> <span class=\"searchresults\">' + lptfound.join(', ') + '</span>';\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>")
2 months ago
content.close()
if __name__ == "__main__":
searchgen()