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.

414 lines
28 KiB
Python

import os
import cardstring,gamesort,gameskel,variables
from pathlib import Path
from datetime import datetime,timedelta
"""
Generates backlog page
"""
home = str(Path.home())
def backlog(local=False):
# delete existing file
if not os.path.isdir("gamebuild/backlog"):
os.mkdir("gamebuild/backlog")
if os.path.exists("gamebuild/backlog/index.html"):
os.remove("gamebuild/backlog/index.html")
# write header
gameskel.headerwrite("gamebuild/backlog/index.html","backlog",local)
output = "gamebuild/backlog/index.html"
filewrite = open(output, "a")
filewrite.write(" <section>\n <div>\n <h1>Now Playing</h1>\n <div class=\"now-playing\">\n")
playingnow = []
def nowplaying():
for console in gamesort.consolelists:
if len(console["games"]) > 0:
thegame = (console["games"])[-1]
try:
if thegame["gameplay"] > (datetime.now() - timedelta(days=180)):
try:
if thegame["completed"]:
if thegame["completed"] >= thegame["gameplay"]:
playing = False
else:
playing = True
except:
try:
if thegame["beaten"]:
if thegame["beaten"] >= thegame["gameplay"]:
playing = False
else:
playing = True
except:
playing = True
else:
playing = False
except:
playing = False
if playing == True:
playingnow.append(thegame)
nowplaying()
playingnow = sorted(playingnow,key=lambda d: d["lastupdate"],reverse=True)
for game in playingnow:
if playingnow.index(game) == 0:
filewrite.write(cardstring.playcard(game,local))
else:
filewrite.write(cardstring.playcard(game,local,True))
filewrite.write(" </div>\n")
# BACKLOG BREAKDOWN
filewrite.write(" <h1>Backlog Breakdown</h1>\n <div class=\"backlog-breakdown\">\n <div class=\"backlog-charts\">\n <div class=\"mem-sum\">\n <div class=\"donut\">\n <svg viewBox=\"0 0 42 42\">\n <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/index.html")
else:
filewrite.write(variables.gameserverpath + "library")
filewrite.write("\"><text x=\"21\" y=\"17.5\" style=\"font-size: 3.5px; opacity: 0.75; text-anchor: middle;\">Total Games</text>\n <text x=\"21\" y=\"27\" style=\"font-size: 10px; text-anchor: middle;\">" + str(len(gamesort.games)) + "</text>\n <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"4\" stroke=\"#000000c0\" fill=\"transparent\">\n </circle>\n")
backlog = gamesort.unfinished(gamesort.games) + gamesort.unplayed(gamesort.games)
takeup = 100
if gamesort.unplayed(gamesort.games) > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(200, 30%, 30%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(takeup) + " 100\">\n </circle>\n")
takeup = takeup - round(((gamesort.unplayed(gamesort.games)/gamesort.total(gamesort.games))*100),1)
if gamesort.unfinished(gamesort.games) > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(0, 38%, 35%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(takeup) + " 100\">\n </circle>\n")
takeup = takeup - round(((gamesort.unfinished(gamesort.games)/gamesort.total(gamesort.games))*100),1)
if gamesort.beaten(gamesort.games) > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(0, 0%, 82%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(takeup) + " 100\">\n </circle>\n")
takeup = takeup - round(((gamesort.beaten(gamesort.games)/gamesort.total(gamesort.games))*100),1)
if gamesort.completed(gamesort.games) > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(48, 75%, 70%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(takeup) + " 100\">\n </circle>\n")
takeup = takeup - round(((gamesort.completed(gamesort.games)/gamesort.total(gamesort.games))*100),1)
if gamesort.endless(gamesort.games) > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(275, 39%, 32%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(takeup) + " 100\">\n </circle>\n")
yeargames = 0
yearplaying = 0
for game in gamesort.games:
if game["initialdate"].year == int(gamesort.thisyear):
try:
if game["gameplay"]:
if game["id"] not in variables.endlessgames:
yeargames += 1
except:
yeargames += 1
for game in gamesort.games:
try:
if game["beaten"].year == int(gamesort.thisyear):
yeargames -= 1
except:
try:
if game["completed"].year == int(gamesort.thisyear):
yeargames -= 1
except:
pass
filewrite.write(" </a></svg>\n </div>\n <div class=\"donut\">\n <svg viewBox=\"0 0 42 42\">\n <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/history/index.html")
else:
filewrite.write(variables.gameserverpath + "history")
filewrite.write("\"><text x=\"21\" y=\"17.5\" style=\"font-size: 3.5px; opacity: 0.75; text-anchor: middle;\">" + gamesort.thisyear + " Backlog</text>\n <text x=\"21\" y=\"27\" style=\"font-size: 10px; text-anchor: middle;\">")
if yeargames > 0:
filewrite.write("")
elif yeargames < 0:
filewrite.write("")
filewrite.write(str(abs(yeargames)) + "</text>\n <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"4\" stroke=\"#000000c0\" fill=\"transparent\">\n </circle>\n")
yearbacklog = []
for game in gamesort.games:
try:
if game["completed"].year == int(gamesort.thisyear):
yearbacklog.append(game)
except:
try:
if game["beaten"].year == int(gamesort.thisyear):
yearbacklog.append(game)
except:
if game["initialdate"].year == int(gamesort.thisyear):
yearbacklog.append(game)
yearcompleted = 0
yearbeaten = 0
yearendless = 0
yearunfinished = 0
yeartotal = len(yearbacklog)
if yeartotal > 0:
for game in yearbacklog:
try:
if game["completed"]:
yearcompleted += 1
except:
try:
if game["beaten"]:
yearbeaten += 1
except:
try:
if game["gameplay"]:
if game["id"] in variables.endlessgames:
yearendless += 1
else:
yearunfinished += 1
except:
pass
yearunplayed = yeartotal - (yearcompleted + yearbeaten + yearunfinished + yearendless)
yeartakeup = 100
if yearunplayed > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(200, 30%, 30%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(yeartakeup) + " 100\">\n </circle>\n")
yeartakeup = yeartakeup - round(((yearunplayed/yeartotal)*100),1)
if yearunfinished > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(0, 38%, 35%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(yeartakeup) + " 100\">\n </circle>\n")
yeartakeup = yeartakeup - round(((yearunfinished/yeartotal)*100),1)
if yearbeaten > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(0, 0%, 82%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(yeartakeup) + " 100\">\n </circle>\n")
yeartakeup = yeartakeup - round(((yearbeaten/yeartotal)*100),1)
if yearcompleted > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(48, 75%, 70%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(yeartakeup) + " 100\">\n </circle>\n")
yeartakeup = yeartakeup - round(((yearcompleted/yeartotal)*100),1)
if yearendless > 0:
filewrite.write(" <circle id=\"circle\" r=\"15.91549430918954\" cy=\"21\" cx=\"21\" stroke-width=\"3\" stroke=\"hsla(275, 39%, 32%, 0.9)\" fill=\"transparent\" stroke-dasharray=\"" + str(yeartakeup) + " 100\">\n </circle>\n")
filewrite.write(" </a></svg>\n </div>\n </div>\n <div class=\"status-tally\">\n <div class=\"backlog-tally\">\n <div style=\"width: " + str(round(((backlog/gamesort.total(gamesort.games))*100),1)) + "%;\">")
if ((backlog/gamesort.total(gamesort.games))*100) > 50:
filewrite.write("\n <span>Total Backlog · " + str(backlog) + " · " + str(round(((backlog/gamesort.total(gamesort.games))*100),1)) + "%</span>")
filewrite.write("\n </div>\n <div style=\"width: " + str(100 - round(((backlog/gamesort.total(gamesort.games))*100),1)) + "%;\">")
if ((backlog/gamesort.total(gamesort.games))*100) <= 50:
filewrite.write("\n <span>Active Backlog · " + str(backlog) + " · " + str(round(((backlog/gamesort.total(gamesort.games))*100),1)) + "%</span>")
filewrite.write("\n </div>\n </div>\n")
compare = []
compare.append(gamesort.unplayed(gamesort.games))
compare.append(gamesort.unfinished(gamesort.games))
compare.append(gamesort.beaten(gamesort.games))
compare.append(gamesort.completed(gamesort.games))
compare.append(gamesort.endless(gamesort.games))
maxvalue = max(compare)
if gamesort.unplayed(gamesort.games) / maxvalue > 0.5:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-unplayed/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-unplayed")
filewrite.write("\">\n <div>" + str(gamesort.unplayed(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("UP.png\">\n </div>\n <div>\n <div class=\"Unplayed\" style=\"width: calc(100% * (" + str(gamesort.unplayed(gamesort.games)) + " / " + str(maxvalue) + "));\">" + str(round(((gamesort.unplayed(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Unplayed</div>\n </div>\n </a>\n")
else:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-unplayed/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-unplayed")
filewrite.write("\">\n <div>" + str(gamesort.unplayed(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("UP.png\">\n </div>\n <div>\n <div class=\"Unplayed\" style=\"width: calc(100% * (" + str(gamesort.unplayed(gamesort.games)) + " / " + str(maxvalue) + "));\">\n </div>\n <div class=\"borderless\">" + str(round(((gamesort.unplayed(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Unplayed</div>\n </div>\n </a>\n")
if gamesort.unfinished(gamesort.games) / maxvalue > 0.5:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-unfinished/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-unfinished")
filewrite.write("\">\n <div>" + str(gamesort.unfinished(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("UF.png\">\n </div>\n <div>\n <div class=\"Unfinished\" style=\"width: calc(100% * (" + str(gamesort.unfinished(gamesort.games)) + " / " + str(maxvalue) + "));\">" + str(round(((gamesort.unfinished(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Unfinished</div>\n </div>\n </a>\n")
else:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-unfinished/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-unfinished")
filewrite.write("\">\n <div>" + str(gamesort.unfinished(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("UF.png\">\n </div>\n <div>\n <div class=\"Unfinished\" style=\"width: calc(100% * (" + str(gamesort.unfinished(gamesort.games)) + " / " + str(maxvalue) + "));\">\n </div>\n <div class=\"borderless\">" + str(round(((gamesort.unfinished(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Unfinished</div>\n </div>\n </a>\n")
if gamesort.beaten(gamesort.games) / maxvalue > 0.5:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-beaten/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-beaten")
filewrite.write("\">\n <div>" + str(gamesort.beaten(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("B.png\">\n </div>\n <div>\n <div class=\"Beaten\" style=\"width: calc(100% * (" + str(gamesort.beaten(gamesort.games)) + " / " + str(maxvalue) + "));\">" + str(round(((gamesort.beaten(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Beaten</div>\n </div>\n </a>\n")
else:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-beaten/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-beaten")
filewrite.write("\">\n <div>" + str(gamesort.beaten(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("B.png\">\n </div>\n <div>\n <div class=\"Beaten\" style=\"width: calc(100% * (" + str(gamesort.beaten(gamesort.games)) + " / " + str(maxvalue) + "));\">\n </div>\n <div class=\"borderless\">" + str(round(((gamesort.beaten(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Beaten</div>\n </div>\n </a>\n")
if gamesort.completed(gamesort.games) / maxvalue > 0.5:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-completed/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-completed")
filewrite.write("\">\n <div>" + str(gamesort.completed(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("C.png\">\n </div>\n <div>\n <div class=\"Completed\" style=\"width: calc(100% * (" + str(gamesort.completed(gamesort.games)) + " / " + str(maxvalue) + "));\">" + str(round(((gamesort.completed(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Completed</div>\n </div>\n </a>\n")
else:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-completed/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-completed")
filewrite.write("\">\n <div>" + str(gamesort.completed(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("C.png\">\n </div>\n <div>\n <div class=\"Completed\" style=\"width: calc(100% * (" + str(gamesort.completed(gamesort.games)) + " / " + str(maxvalue) + "));\">\n </div>\n <div class=\"borderless\">" + str(round(((gamesort.completed(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Completed</div>\n </div>\n </a>\n")
if gamesort.endless(gamesort.games) / maxvalue > 0.5:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-endless/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-endless")
filewrite.write("\">\n <div>" + str(gamesort.endless(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("E.png\">\n </div>\n <div>\n <div class=\"Endless\" style=\"width: calc(100% * (" + str(gamesort.endless(gamesort.games)) + " / " + str(maxvalue) + "));\">" + str(round(((gamesort.endless(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Endless</div>\n </div>\n </a>\n")
else:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-endless/index.html")
else:
filewrite.write(variables.gameserverpath + "library/all-endless")
filewrite.write("\">\n <div>" + str(gamesort.endless(gamesort.games)) + "</div>\n <div>\n <img src=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/")
else:
filewrite.write(variables.gameserverpath)
filewrite.write("E.png\">\n </div>\n <div>\n <div class=\"Endless\" style=\"width: calc(100% * (" + str(gamesort.endless(gamesort.games)) + " / " + str(maxvalue) + "));\">\n </div>\n <div class=\"borderless\">" + str(round(((gamesort.endless(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Endless</div>\n </div>\n </a>\n")
filewrite.write(" </div>\n </div>\n </div>\n")
# PLATFORM SUMMARY
filewrite.write(" <h1>Platform Summary</h1>\n <div class=\"platform-summary\">\n")
listofconsoles = sorted(variables.consoles,key=lambda d: d["name"])
for console in listofconsoles:
consolegames = []
for game in gamesort.games:
if game["console"] == console["code"]:
consolegames.append(game)
ccompleted = 0
cbeaten = 0
cendless = 0
cunfinished = 0
ctotal = len(consolegames)
if ctotal > 0:
filewrite.write(" <div class=\"platform-card\">\n <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/" + console["shortname"].lower() + "-all/index.html")
else:
filewrite.write(variables.gameserverpath + "library/" + console["shortname"].lower() + "-all")
filewrite.write("\" class=\"title\">" + console["name"] + "</a>\n <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/" + console["shortname"].lower() + "-all/index.html")
else:
filewrite.write(variables.gameserverpath + "library/" + console["shortname"].lower() + "-all")
filewrite.write("\"class=\"abbr\">" + console["shortname"] + "</a>\n <div class=\"bars\">\n")
for game in consolegames:
try:
if game["completed"]:
ccompleted += 1
except:
try:
if game["beaten"]:
cbeaten += 1
except:
try:
if game["gameplay"]:
if game["id"] in variables.endlessgames:
cendless += 1
else:
cunfinished += 1
except:
pass
cunplayed = ctotal - (ccompleted + cbeaten + cunfinished + cendless)
if cunplayed > 0:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/" + console["shortname"].lower() + "-unplayed/index.html")
else:
filewrite.write(variables.gameserverpath + "library/" + console["shortname"].lower() + "-unplayed")
filewrite.write("\" class=\"unplayed\" title=\"Unplayed\" style=\"flex: " + str(cunplayed) + " 1 0%;\">" + str(cunplayed) + "</a>\n")
if cunfinished > 0:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/" + console["shortname"].lower() + "-unfinished/index.html")
else:
filewrite.write(variables.gameserverpath + "library/" + console["shortname"].lower() + "-unfinished")
filewrite.write("\" class=\"unfinished\" title=\"Unfinished\" style=\"flex: " + str(cunfinished) + " 1 0%;\">" + str(cunfinished) + "</a>\n")
if cbeaten > 0:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/" + console["shortname"].lower() + "-beaten/index.html")
else:
filewrite.write(variables.gameserverpath + "library/" + console["shortname"].lower() + "-beaten")
filewrite.write("\"class=\"beaten\" title=\"Beaten\" style=\"flex: " + str(cbeaten) + " 1 0%;\">" + str(cbeaten) + "</a>\n")
if ccompleted > 0:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/" + console["shortname"].lower() + "-completed/index.html")
else:
filewrite.write(variables.gameserverpath + "library/" + console["shortname"].lower() + "-completed")
filewrite.write("\" class=\"completed\" title=\"Completed\" style=\"flex: " + str(ccompleted) + " 1 0%;\">" + str(ccompleted) + "</a>\n")
if cendless > 0:
filewrite.write(" <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/" + console["shortname"].lower() + "-endless/index.html")
else:
filewrite.write(variables.gameserverpath + "library/" + console["shortname"].lower() + "-endless")
filewrite.write("\" class=\"endless\" title=\"Endless\" style=\"flex: " + str(cendless) + " 1 0%;\">" + str(cendless) + "</a>\n")
filewrite.write(" </div>\n <a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/" + console["shortname"].lower() + "-all/index.html")
else:
filewrite.write(variables.gameserverpath + "library/" + console["shortname"].lower() + "-all")
filewrite.write("\" class=\"total\">" + str(ctotal) + "\n <span>Total</span>\n </a>\n </div>\n")
filewrite.write(" </div>\n </div>\n </div>\n")
filewrite.close()
gameskel.footerwrite("gamebuild/backlog/index.html")
if __name__ == "__main__":
backlog(True)