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.

276 lines
11 KiB
Python

import datetime,os,re
from collections import Counter
import log,skel,variables,tcgcore
4 weeks ago
def indexgen():
if os.path.exists("build/index.html"):
os.remove("build/index.html")
thefile = "build/index.html"
skel.headerwrite(thefile,"index")
content = open(thefile,"a")
firstdate = log.log[0]["date"]
if len(tcgcore.ownedcards()) > 14400:
rankcode = "rainbow"
extra = len(tcgcore.ownedcards()) - 14400
plusranks = int(extra / 300)
if plusranks > 0:
rank = "rainbow + " + str(plusranks)
else:
rank = "rainbow"
else:
if len(tcgcore.ownedcards()) > 14100:
rank = "himalayan"
elif len(tcgcore.ownedcards()) > 13800:
rank = "puma"
elif len(tcgcore.ownedcards()) > 13500:
rank = "chartreux"
elif len(tcgcore.ownedcards()) > 13500:
rank = "russian blue"
elif len(tcgcore.ownedcards()) > 12900:
rank = "panther"
elif len(tcgcore.ownedcards()) > 12600:
rank = "cheetah"
elif len(tcgcore.ownedcards()) > 12300:
rank = "tiger"
elif len(tcgcore.ownedcards()) > 12000:
rank = "lion"
elif len(tcgcore.ownedcards()) > 11700:
rank = "metal"
elif len(tcgcore.ownedcards()) > 11400:
rank = "ground"
elif len(tcgcore.ownedcards()) > 11100:
rank = "darkness"
elif len(tcgcore.ownedcards()) > 10800:
rank = "water"
elif len(tcgcore.ownedcards()) > 10500:
rank = "nature"
elif len(tcgcore.ownedcards()) > 10200:
rank = "light"
elif len(tcgcore.ownedcards()) > 9900:
rank = "wind"
elif len(tcgcore.ownedcards()) > 9600:
rank = "fire"
elif len(tcgcore.ownedcards()) > 9300:
rank = "mercury"
elif len(tcgcore.ownedcards()) > 9000:
rank = "jupiter"
elif len(tcgcore.ownedcards()) > 8700:
rank = "uranus"
elif len(tcgcore.ownedcards()) > 8400:
rank = "neptune"
elif len(tcgcore.ownedcards()) > 8100:
rank = "earth"
elif len(tcgcore.ownedcards()) > 7800:
rank = "venus"
elif len(tcgcore.ownedcards()) > 7500:
rank = "saturn"
elif len(tcgcore.ownedcards()) > 7200:
rank = "mars"
elif len(tcgcore.ownedcards()) > 6900:
rank = "magnolia"
elif len(tcgcore.ownedcards()) > 6600:
rank = "chocolate cosmos"
elif len(tcgcore.ownedcards()) > 6300:
rank = "lilac"
elif len(tcgcore.ownedcards()) > 6000:
rank = "hydrangea"
elif len(tcgcore.ownedcards()) > 5700:
rank = "clover"
elif len(tcgcore.ownedcards()) > 5400:
rank = "daffodil"
elif len(tcgcore.ownedcards()) > 5100:
rank = "tiger lily"
elif len(tcgcore.ownedcards()) > 4800:
rank = "sakura"
elif len(tcgcore.ownedcards()) > 4500:
rank = "silver"
elif len(tcgcore.ownedcards()) > 4200:
rank = "bronze"
elif len(tcgcore.ownedcards()) > 3900:
rank = "amethyst"
elif len(tcgcore.ownedcards()) > 3600:
rank = "sapphire"
elif len(tcgcore.ownedcards()) > 3300:
rank = "emerald"
elif len(tcgcore.ownedcards()) > 3000:
rank = "gold"
elif len(tcgcore.ownedcards()) > 2700:
rank = "amber"
elif len(tcgcore.ownedcards()) > 2400:
rank = "ruby"
elif len(tcgcore.ownedcards()) > 2200:
rank = "dragon fruit"
elif len(tcgcore.ownedcards()) > 2000:
rank = "apricot"
elif len(tcgcore.ownedcards()) > 1800:
rank = "grape"
elif len(tcgcore.ownedcards()) > 1600:
rank = "blueberry"
elif len(tcgcore.ownedcards()) > 1400:
rank = "lime"
elif len(tcgcore.ownedcards()) > 1200:
rank = "lemon"
elif len(tcgcore.ownedcards()) > 1000:
rank = "tangerine"
elif len(tcgcore.ownedcards()) > 800:
rank = "strawberry"
elif len(tcgcore.ownedcards()) > 700:
rank = "gray"
elif len(tcgcore.ownedcards()) > 600:
rank = "brown"
elif len(tcgcore.ownedcards()) > 500:
rank = "purple"
elif len(tcgcore.ownedcards()) > 400:
rank = "blue"
elif len(tcgcore.ownedcards()) > 300:
rank = "green"
elif len(tcgcore.ownedcards()) > 200:
rank = "yellow"
elif len(tcgcore.ownedcards()) > 100:
rank = "orange"
else:
rank = "red"
rankcode = re.sub(" ","",rank)
content.write("<a href=\"/levels\"><img src=\"/assets/levels/" + rankcode + ".gif\"></a>" + tcgcore.printcard("sig_" + variables.name.lower()) + "\n<ul>\n<li>player name: " + variables.name + "</li>\n<li>" + str(len(tcgcore.ownedcards())) + " cards held (" + rank + ")</li>\n<li>started <code>" + firstdate.strftime("%Y-%m-%d") + "</code></li>\n<li>last updated <code>" + datetime.datetime.today().strftime("%Y-%m-%d") + "</code></li>\n<li><a href=\"https://git.praze.net/tre/tcg\">code</a> under construction</li>\n</ul>\n")
crayred = 0
crayorange = 0
crayyellow = 0
craygreen = 0
crayblue = 0
craypurple = 0
craybrown = 0
craygrey = 0
for event in log.log:
try:
crayred += event["crayons"]["red"]
except:
pass
try:
crayorange += event["crayons"]["orange"]
except:
pass
try:
crayyellow += event["crayons"]["yellow"]
except:
pass
try:
craygreen += event["crayons"]["green"]
except:
pass
try:
crayblue += event["crayons"]["blue"]
except:
pass
try:
craypurple += event["crayons"]["purple"]
except:
pass
try:
craybrown += event["crayons"]["brown"]
except:
pass
try:
craygrey += event["crayons"]["gray"]
except:
pass
if crayred + crayorange + crayyellow + craygreen + crayblue + craypurple + craybrown + craygrey > 0:
content.write("<table id=\"crayontable\">\n<tbody>\n<tr>\n")
if crayred > 0:
content.write("<td><img src=\"/assets/crayons/crayon1.gif\" class=\"crayon\" title=\"red\"> × " + str(crayred) + "</td>\n")
if crayorange > 0:
content.write("<td><img src=\"/assets/crayons/crayon2.gif\" class=\"crayon\" title=\"orange\"> × " + str(crayorange) + "</td>\n")
if crayyellow > 0:
content.write("<td><img src=\"/assets/crayons/crayon3.gif\" class=\"crayon\" title=\"yellow\"> × " + str(crayyellow) + "</td>\n")
if craygreen > 0:
content.write("<td><img src=\"/assets/crayons/crayon4.gif\" class=\"crayon\" title=\"green\"> × " + str(craygreen) + "</td>\n")
if crayblue > 0:
content.write("<td><img src=\"/assets/crayons/crayon5.gif\" class=\"crayon\" title=\"blue\"> × " + str(crayblue) + "</td>\n")
if craypurple > 0:
content.write("<td><img src=\"/assets/crayons/crayon6.gif\" class=\"crayon\" title=\"purple\"> × " + str(craypurple) + "</td>\n")
if craybrown > 0:
content.write("<td><img src=\"/assets/crayons/crayon7.gif\" class=\"crayon\" title=\"brown\"> × " + str(craybrown) + "</td>\n")
if craygrey > 0:
content.write("<td><img src=\"/assets/crayons/crayon8.gif\" class=\"crayon\" title=\"")
if variables.british:
content.write("grey")
else:
content.write("gray")
content.write("\"> × " + str(craygrey) + "</td>\n")
content.write("</tr>\n</tbody>\n</table>\n")
tradeout = []
tradein = []
for event in log.log:
if event["event"][0:11] == "trade with ":
try:
for card in event["lost"]:
tradeout.append(event["event"])
except:
pass
try:
for card in event["received"]:
tradein.append(event["event"])
except:
pass
tradecommon = list((Counter(tradeout) & Counter(tradein)).elements())
sketch = len(tradecommon)
if sketch > 0:
content.write("<table class=\"sketchpads\">\n<tbody>\n<tr>\n<td><img src=\"/assets/sketch/")
if sketch % 20 < 10:
content.write("0" + str(sketch % 20))
else:
content.write(str(sketch % 20))
content.write(".gif\"></td>\n")
if sketch > 19:
content.write("<td><img src=\"/assets/sketch/20.gif\"></td>\n")
content.write("</tr>\n<tr>\n<td align=\"center\">" + str(sketch % 20) + "/20</td>\n")
if sketch > 19:
content.write("<td align=\"center\">" + str(int(sketch / 20)) + " completed</td>\n")
content.write("</tr>\n</tbody>\n</table>")
if len(tcgcore.getpalettes()) + len(tcgcore.getmonochrome()) > 0:
3 weeks ago
content.write("<a href=\"/portfolios\">\n<div class=\"foliocase\">\n")
if len(tcgcore.getpalettes()) > 0:
content.write(tcgcore.portfoliogen(tcgcore.getpalettes()[-1],"palette",len(tcgcore.getpalettes())))
if len(tcgcore.getmonochrome()) > 0:
content.write(tcgcore.portfoliogen(tcgcore.getmonochrome()[-1],"monochrome",len(tcgcore.getmonochrome())))
content.write("</div>\n</a>\n")
decksofinterest = []
for card in tcgcore.ownedcards():
if card[0:4] != "sig_":
decksofinterest.append(card[:-2])
decksofinterest = sorted(list(dict.fromkeys(decksofinterest)))
mastereddecks = []
for deck in decksofinterest:
if tcgcore.deckmastered(deck):
mastereddecks.append({"name":deck,"date":tcgcore.datemastered(deck)})
mastereddecks = sorted(mastereddecks,key=lambda d: d["date"],reverse=True)
if len(mastereddecks) > 0:
content.write("<h2>mastered decks</h2>\n<p id=\"masteredcarousel\">")
3 weeks ago
masteredcount = 0
for deck in mastereddecks:
if masteredcount < variables.maxmastered:
content.write("<img src=\"/decks/" + deck["name"] + "/master.gif\" title=\"mastered " + deck["name"] + "\">")
masteredcount += 1
if len(mastereddecks) > variables.maxmastered:
content.write(" <a href=\"mastered\">see all</a>")
content.write("</p>\n")
4 weeks ago
sigs = []
for card in tcgcore.ownedcards():
if card[0:4] == "sig_":
sigs.append(card)
if len(sigs) > 0:
content.write("<h2>signatures</h2>\n<p>")
for card in sigs:
content.write(tcgcore.printcard(card))
content.write("</p>\n")
if len(variables.faves) > 0:
content.write("<h2>faves</h2>\n<p>")
faveslist = sorted(variables.faves)
for card in faveslist:
content.write(tcgcore.printcard(card))
4 weeks ago
content.write("</p>\n")
4 weeks ago
content.close()
skel.footerwrite(thefile)
if __name__ == "__main__":
indexgen()