import os import cardstring,gamesort,skeleton,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("build/backlog"): os.mkdir("build/backlog") if os.path.exists("build/backlog/index.html"): os.remove("build/backlog/index.html") # write header skeleton.headerwrite("build/backlog/index.html","backlog",local) output = "build/backlog/index.html" filewrite = open(output, "a") filewrite.write("
\n
\n

Now Playing

\n
\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("
\n") # BACKLOG BREAKDOWN filewrite.write("

Backlog Breakdown

\n
\n
\n
\n \n \n
\n
\n
\n
") if ((backlog/gamesort.total(gamesort.games))*100) > 50: filewrite.write("\n Total Backlog · " + str(backlog) + " · " + str(round(((backlog/gamesort.total(gamesort.games))*100),1)) + "%") filewrite.write("\n
\n
") if ((backlog/gamesort.total(gamesort.games))*100) <= 50: filewrite.write("\n Active Backlog · " + str(backlog) + " · " + str(round(((backlog/gamesort.total(gamesort.games))*100),1)) + "%") filewrite.write("\n
\n
\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(" \n
" + str(gamesort.unplayed(gamesort.games)) + "
\n
\n \n
\n
\n
" + str(round(((gamesort.unplayed(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Unplayed
\n
\n
\n") else: filewrite.write(" \n
" + str(gamesort.unplayed(gamesort.games)) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((gamesort.unplayed(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Unplayed
\n
\n
\n") if gamesort.unfinished(gamesort.games) / maxvalue > 0.5: filewrite.write(" \n
" + str(gamesort.unfinished(gamesort.games)) + "
\n
\n \n
\n
\n
" + str(round(((gamesort.unfinished(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Unfinished
\n
\n
\n") else: filewrite.write(" \n
" + str(gamesort.unfinished(gamesort.games)) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((gamesort.unfinished(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Unfinished
\n
\n
\n") if gamesort.beaten(gamesort.games) / maxvalue > 0.5: filewrite.write(" \n
" + str(gamesort.beaten(gamesort.games)) + "
\n
\n \n
\n
\n
" + str(round(((gamesort.beaten(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Beaten
\n
\n
\n") else: filewrite.write(" \n
" + str(gamesort.beaten(gamesort.games)) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((gamesort.beaten(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Beaten
\n
\n
\n") if gamesort.completed(gamesort.games) / maxvalue > 0.5: filewrite.write(" \n
" + str(gamesort.completed(gamesort.games)) + "
\n
\n \n
\n
\n
" + str(round(((gamesort.completed(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Completed
\n
\n
\n") else: filewrite.write(" \n
" + str(gamesort.completed(gamesort.games)) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((gamesort.completed(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Completed
\n
\n
\n") if gamesort.endless(gamesort.games) / maxvalue > 0.5: filewrite.write(" \n
" + str(gamesort.endless(gamesort.games)) + "
\n
\n \n
\n
\n
" + str(round(((gamesort.endless(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Endless
\n
\n
\n") else: filewrite.write(" \n
" + str(gamesort.endless(gamesort.games)) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((gamesort.endless(gamesort.games)/gamesort.total(gamesort.games))*100),1)) + "% Endless
\n
\n
\n") filewrite.write("
\n
\n
\n") # PLATFORM SUMMARY filewrite.write("

Platform Summary

\n
\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("
\n " + console["name"] + "\n " + console["shortname"] + "\n
\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(" " + str(cunplayed) + "\n") if cunfinished > 0: filewrite.write(" " + str(cunfinished) + "\n") if cbeaten > 0: filewrite.write(" " + str(cbeaten) + "\n") if ccompleted > 0: filewrite.write(" " + str(ccompleted) + "\n") if cendless > 0: filewrite.write(" " + str(cendless) + "\n") filewrite.write("
\n " + str(ctotal) + "\n Total\n \n
\n") filewrite.write("
\n
\n \n") filewrite.close() skeleton.footerwrite("build/backlog/index.html") if __name__ == "__main__": backlog(True)