Rebuild in modular fashion
This commit is contained in:
parent
cfd5b0ca34
commit
3b5cb360d5
28 changed files with 1238 additions and 694 deletions
151
sublibrary.py
Normal file
151
sublibrary.py
Normal file
|
@ -0,0 +1,151 @@
|
|||
import os
|
||||
import cardstring,gamesort,skeleton,variables
|
||||
from pathlib import Path
|
||||
|
||||
"""
|
||||
Generates sublibrary pages
|
||||
"""
|
||||
|
||||
home = str(Path.home())
|
||||
|
||||
def sublibrary(local=False):
|
||||
statuses = ["all","completed","beaten","unfinished","endless","unplayed"]
|
||||
consoleextra = [{"shortname":"all"}]
|
||||
consolesplus = variables.consoles + consoleextra
|
||||
for console in consolesplus:
|
||||
gameslist = []
|
||||
for game in gamesort.games:
|
||||
if console["shortname"] == "all":
|
||||
gameslist.append(game)
|
||||
elif game["console"] == console["code"]:
|
||||
gameslist.append(game)
|
||||
for status in statuses:
|
||||
filterlist = []
|
||||
if status == "all":
|
||||
for game in gameslist:
|
||||
filterlist.append(game)
|
||||
elif status == "completed":
|
||||
for game in gameslist:
|
||||
try:
|
||||
if game["completed"]:
|
||||
filterlist.append(game)
|
||||
except:
|
||||
pass
|
||||
elif status == "beaten":
|
||||
for game in gameslist:
|
||||
try:
|
||||
if game["completed"]:
|
||||
pass
|
||||
except:
|
||||
try:
|
||||
if game["beaten"]:
|
||||
filterlist.append(game)
|
||||
except:
|
||||
pass
|
||||
elif status == "unfinished":
|
||||
for game in gameslist:
|
||||
try:
|
||||
if game["completed"]:
|
||||
pass
|
||||
except:
|
||||
try:
|
||||
if game["beaten"]:
|
||||
pass
|
||||
except:
|
||||
try:
|
||||
if game["gameplay"]:
|
||||
if game["id"] not in variables.endlessgames:
|
||||
filterlist.append(game)
|
||||
except:
|
||||
pass
|
||||
elif status == "endless":
|
||||
for game in gameslist:
|
||||
try:
|
||||
if game["completed"]:
|
||||
pass
|
||||
except:
|
||||
try:
|
||||
if game["beaten"]:
|
||||
pass
|
||||
except:
|
||||
try:
|
||||
if game["gameplay"]:
|
||||
if game["id"] in variables.endlessgames:
|
||||
filterlist.append(game)
|
||||
except:
|
||||
pass
|
||||
elif status == "unplayed":
|
||||
for game in gameslist:
|
||||
try:
|
||||
if game["completed"]:
|
||||
pass
|
||||
except:
|
||||
try:
|
||||
if game["beaten"]:
|
||||
pass
|
||||
except:
|
||||
try:
|
||||
if game["gameplay"]:
|
||||
pass
|
||||
except:
|
||||
filterlist.append(game)
|
||||
if not os.path.isdir("build/library/" + console["shortname"].lower() + "-" + status):
|
||||
if len(filterlist) > 0:
|
||||
os.mkdir("build/library/" + console["shortname"].lower() + "-" + status)
|
||||
if os.path.exists("build/library/" + console["shortname"].lower() + "-" + status + "/index.html"):
|
||||
os.remove("build/library/" + console["shortname"].lower() + "-" + status + "/index.html")
|
||||
# write header
|
||||
if len(filterlist) > 0:
|
||||
skeleton.headerwrite(("build/library/" + console["shortname"].lower() + "-" + status + "/index.html"),"sublibrary",local)
|
||||
output = "build/library/" + console["shortname"].lower() + "-" + status + "/index.html"
|
||||
filewrite = open(output, "a")
|
||||
filewrite.write(" <section id=\"library-top\" class=\"library\">\n <div>\n <div class=\"filters\">\n <div>Filtered by\n")
|
||||
if console["shortname"] != "all":
|
||||
filewrite.write(" <span class=\"item\"><a href=\"")
|
||||
if status == "all":
|
||||
if local:
|
||||
filewrite.write(variables.localpath + "build/library/index.html")
|
||||
else:
|
||||
filewrite.write(variables.serverpath + "library")
|
||||
else:
|
||||
if local:
|
||||
filewrite.write(variables.localpath + "build/library/all-" + status + "/index.html")
|
||||
else:
|
||||
filewrite.write(variables.serverpath + "library/all-" + status)
|
||||
filewrite.write("\">1 Platform</a></span>\n")
|
||||
if status != "all":
|
||||
filewrite.write(" <span class=\"item\"><a href=\"")
|
||||
if console["shortname"] == "all":
|
||||
if local:
|
||||
filewrite.write(variables.localpath + "build/library/index.html")
|
||||
else:
|
||||
filewrite.write(variables.serverpath + "library")
|
||||
else:
|
||||
if local:
|
||||
filewrite.write(variables.localpath + "build/library/" + console["shortname"].lower() + "-all/index.html")
|
||||
else:
|
||||
filewrite.write(variables.serverpath + "library/" + console["shortname"].lower() + "-all")
|
||||
filewrite.write("\">1 Status</a></span>\n")
|
||||
filewrite.write(" </div>\n</div> <div class=\"unibar\">\n <div>\n <span>Total Found</span> " + str(gamesort.total(filterlist)) + "\n </div>\n")
|
||||
if gamesort.unplayed(filterlist) > 0:
|
||||
filewrite.write(" <div class=\"unplayed\" style=\"flex: " + str(gamesort.unplayed(filterlist)) + " 1 0%;\">" + str(gamesort.unplayed(filterlist)) + "</div>\n")
|
||||
if gamesort.unfinished(filterlist) > 0:
|
||||
filewrite.write(" <div class=\"unfinished\" style=\"flex: " + str(gamesort.unfinished(filterlist)) + " 1 0%;\">" + str(gamesort.unfinished(filterlist)) + "</div>\n")
|
||||
if gamesort.beaten(filterlist) > 0:
|
||||
filewrite.write(" <div class=\"beaten\" style=\"flex: " + str(gamesort.beaten(filterlist)) + " 1 0%;\">" + str(gamesort.beaten(filterlist)) + "</div>\n")
|
||||
if gamesort.completed(filterlist) > 0:
|
||||
filewrite.write(" <div class=\"completed\" style=\"flex: " + str(gamesort.completed(filterlist)) + " 1 0%;\">" + str(gamesort.completed(filterlist)) + "</div>\n")
|
||||
if gamesort.endless(filterlist) > 0:
|
||||
filewrite.write(" <div class=\"endless\" style=\"flex: " + str(gamesort.endless(filterlist)) + " 1 0%;\">" + str(gamesort.endless(filterlist)) + "</div>\n")
|
||||
filewrite.write(" </div>\n <div class=\"library-list sorted\">\n")
|
||||
|
||||
newgames = sorted(filterlist,key=lambda d: d["id"])
|
||||
|
||||
for game in newgames:
|
||||
filewrite.write(cardstring.playcard(game,local))
|
||||
|
||||
filewrite.close()
|
||||
skeleton.footerwrite("build/library/" + console["shortname"].lower() + "-" + status + "/index.html")
|
||||
|
||||
if __name__ == "__main__":
|
||||
sublibrary(True)
|
Loading…
Add table
Add a link
Reference in a new issue