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.

66 lines
3.5 KiB
Python

import os
import cardstring,gamesort,skeleton,variables
"""
Generates library page
"""
def library(local=False):
# delete existing file
if not os.path.isdir("gamebuild/library"):
os.mkdir("gamebuild/library")
if os.path.exists("gamebuild/library/index.html"):
os.remove("gamebuild/library/index.html")
# write header
skeleton.headerwrite("gamebuild/library/index.html","library",local)
output = "gamebuild/library/index.html"
filewrite = open(output, "a")
filewrite.write(" <section id=\"library-top\" class=\"library\">\n <div>\n <div class=\"unibar\">\n <div>\n <span>Total Found</span> " + str(gamesort.total(gamesort.games)) + "\n </div>\n")
if gamesort.unplayed(gamesort.games) > 0:
filewrite.write(" <div class=\"unplayed\" style=\"flex: " + str(gamesort.unplayed(gamesort.games)) + " 1 0%;\"><a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-unplayed/index.html")
else:
filewrite.write(variables.serverpath + "library/all-unplayed")
filewrite.write("\">" + str(gamesort.unplayed(gamesort.games)) + "</a></div>\n")
if gamesort.unfinished(gamesort.games) > 0:
filewrite.write(" <div class=\"unfinished\" style=\"flex: " + str(gamesort.unfinished(gamesort.games)) + " 1 0%;\"><a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-unfinished/index.html")
else:
filewrite.write(variables.serverpath + "library/all-unfinished")
filewrite.write("\">" + str(gamesort.unfinished(gamesort.games)) + "</a></div>\n")
if gamesort.beaten(gamesort.games) > 0:
filewrite.write(" <div class=\"beaten\" style=\"flex: " + str(gamesort.beaten(gamesort.games)) + " 1 0%;\"><a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-beaten/index.html")
else:
filewrite.write(variables.serverpath + "library/all-beaten")
filewrite.write("\">" + str(gamesort.beaten(gamesort.games)) + "</a></div>\n")
if gamesort.completed(gamesort.games) > 0:
filewrite.write(" <div class=\"completed\" style=\"flex: " + str(gamesort.completed(gamesort.games)) + " 1 0%;\"><a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-completed/index.html")
else:
filewrite.write(variables.serverpath + "library/all-completed")
filewrite.write("\">" + str(gamesort.completed(gamesort.games)) + "</a></div>\n")
if gamesort.endless(gamesort.games) > 0:
filewrite.write(" <div class=\"endless\" style=\"flex: " + str(gamesort.endless(gamesort.games)) + " 1 0%;\"><a href=\"")
if local:
filewrite.write(variables.localpath + "gamebuild/library/all-endless/index.html")
else:
filewrite.write(variables.serverpath + "library/all-endless")
filewrite.write("\">" + str(gamesort.endless(gamesort.games)) + "</a></div>\n")
filewrite.write(" </div>\n <div class=\"library-list sorted\">\n")
newgames = sorted(gamesort.games,key=lambda d: d["id"])
for game in newgames:
filewrite.write(cardstring.playcard(game,local))
filewrite.close()
skeleton.footerwrite("gamebuild/library/index.html")
if __name__ == "__main__":
library(True)