diff --git a/.gitignore b/.gitignore index 0e9d6bf..fc612dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ __pycache__/ build.sh -build/* -!build/*.css -!build/*.png +gamebuild/* +!gamebuild/*.css +!gamebuild/*.png variables.py \ No newline at end of file diff --git a/README.org b/README.org index 390679a..fec1a6b 100644 --- a/README.org +++ b/README.org @@ -4,25 +4,29 @@ - =python3= - =orgparse= (install via pip) - =rclone= (for syncing to the server) -* Tracking games with a backloggery clone -** Setup -*** Fonts -Upload the fonts Lato, Titillium Web, and Material Icons to the directory =/fonts= on your server (I recommend [[https://gwfh.mranftl.com/fonts][google-webfonts-helper]]). Check the filenames are consistent with those in =build/backloggery.css=. Alternatively, you can load the fonts remotely and adjust the page head HTML generated by =skeleton.py=. +* General setup *** Setting the variables Rename =variables-template.py= to =variables.py= and edit: -- =endlessgames=: a list of “endless” games in the format =title (console)= - =orgpath=: absolute path to the root directory in which =.org= files are stored, including trailing slash - =localpath=: absolute path to this directory, including trailing slash -- =serverpath=: path to directory on the server where files will be uploaded, including trailing slash - =domain=: =https://yourdomain.tld= without trailing slash - =rclonesiteroot=: path =rclone= uses to access your webserver +* Tracking games with a backloggery clone +** Setup +*** Fonts +Upload the fonts Lato, Titillium Web, and Material Icons to the directory =/fonts= on your server (I recommend [[https://gwfh.mranftl.com/fonts][google-webfonts-helper]]). Check the filenames are consistent with those in =build/backloggery.css=. Alternatively, you can load the fonts remotely and adjust the page head HTML generated by =skeleton.py=. +*** Setting the variables +In =variables.py=, edit: +- =trackgames=: set to =True= +- =gameserverpath=: path to directory on the server where files will be uploaded, including trailing slash +- =endlessgames=: a list of “endless” games in the format =title (console)= - =description=: content for the “about” section (can include HTML tags) - =startyear=: year from which to begin tracking (an integer) - =hue=: theme colour expressed as a hue from 0 to 360 - =consoles=: add or remove consoles following the format provided (=.png= images must be added to the build directory with a filename corresponding with the value of ="img"= for each console) -*** The rest +* First run - Run =python3 init.py= and then =chmod +x build.sh=. -- Create the directory on the server. -** Generating the files -- Run =python3 generate.py local= to build in the local =build= directory. +- Create directories on the server corresponding to any =*serverpath= variables you have set.. +* Generating the files +- Run =python3 generate.py local= to build in local directories. - Run =./build.sh= to build and upload to the server. diff --git a/backlog.py b/backlog.py index 636f2a3..05bd707 100644 --- a/backlog.py +++ b/backlog.py @@ -1,5 +1,5 @@ import os -import cardstring,gamesort,skeleton,variables +import cardstring,gamesort,gameskel,variables from pathlib import Path from datetime import datetime,timedelta @@ -11,13 +11,13 @@ 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") + 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 - skeleton.headerwrite("build/backlog/index.html","backlog",local) - output = "build/backlog/index.html" + gameskel.headerwrite("gamebuild/backlog/index.html","backlog",local) + output = "gamebuild/backlog/index.html" filewrite = open(output, "a") filewrite.write("
\n
\n

Now Playing

\n
\n") playingnow = [] @@ -65,9 +65,9 @@ def backlog(local=False): filewrite.write("

Backlog Breakdown

\n
\n
\n
\n \n
\n \n " + gamesort.thisyear + " Backlog\n ") if yeargames > 0: @@ -194,126 +194,126 @@ def backlog(local=False): 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") @@ -337,14 +337,14 @@ def backlog(local=False): if ctotal > 0: filewrite.write("
\n " + console["name"] + "\n " + console["shortname"] + "\n
\n") for game in consolegames: try: @@ -367,47 +367,47 @@ def backlog(local=False): 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") + gameskel.footerwrite("gamebuild/backlog/index.html") if __name__ == "__main__": backlog(True) diff --git a/cardstring.py b/cardstring.py index 56f5da1..938a0be 100644 --- a/cardstring.py +++ b/cardstring.py @@ -15,27 +15,27 @@ def playcard(game,local=False,decay=False): if game["console"] == console["code"]: cardstring += " \""\n" cardstring += " \n \n
\n" try: if game["completed"]: cardstring += " \"C\"\n" except: try: if game["beaten"]: cardstring += " \"B\"\n" except: try: @@ -43,23 +43,23 @@ def playcard(game,local=False,decay=False): if game["id"] in variables.endlessgames: cardstring += " \"E\"\n" else: cardstring += " \"UF\"\n" except: cardstring += " \"UP\"\n" cardstring += "
\n
\n
" + game["name"] + "
\n" try: @@ -77,9 +77,9 @@ def playcard(game,local=False,decay=False): else: cardstring += "
\n
\n \"⯈\"\n
\n" else: cardstring += " \n
\n \n
\n" @@ -92,9 +92,9 @@ def playcard(game,local=False,decay=False): else: cardstring += " \n
\n \"⯈\"\n
\n" else: cardstring += " \n
\n \n
\n" @@ -105,16 +105,16 @@ def playcard(game,local=False,decay=False): else: cardstring += " \n
\n \"⏸\"\n
\n" else: cardstring += " \n
\n \"⯈\"\n
\n" except: cardstring += " \n
\n \n
\n" diff --git a/build/360.png b/gamebuild/360.png similarity index 100% rename from build/360.png rename to gamebuild/360.png diff --git a/build/3DS.png b/gamebuild/3DS.png similarity index 100% rename from build/3DS.png rename to gamebuild/3DS.png diff --git a/build/B.png b/gamebuild/B.png similarity index 100% rename from build/B.png rename to gamebuild/B.png diff --git a/build/C.png b/gamebuild/C.png similarity index 100% rename from build/C.png rename to gamebuild/C.png diff --git a/build/E.png b/gamebuild/E.png similarity index 100% rename from build/E.png rename to gamebuild/E.png diff --git a/build/NDS.png b/gamebuild/NDS.png similarity index 100% rename from build/NDS.png rename to gamebuild/NDS.png diff --git a/build/PC.png b/gamebuild/PC.png similarity index 100% rename from build/PC.png rename to gamebuild/PC.png diff --git a/build/PS2.png b/gamebuild/PS2.png similarity index 100% rename from build/PS2.png rename to gamebuild/PS2.png diff --git a/build/PS3.png b/gamebuild/PS3.png similarity index 100% rename from build/PS3.png rename to gamebuild/PS3.png diff --git a/build/PS5.png b/gamebuild/PS5.png similarity index 100% rename from build/PS5.png rename to gamebuild/PS5.png diff --git a/build/Switch.png b/gamebuild/Switch.png similarity index 100% rename from build/Switch.png rename to gamebuild/Switch.png diff --git a/build/UF.png b/gamebuild/UF.png similarity index 100% rename from build/UF.png rename to gamebuild/UF.png diff --git a/build/UP.png b/gamebuild/UP.png similarity index 100% rename from build/UP.png rename to gamebuild/UP.png diff --git a/build/backloggery.css b/gamebuild/backloggery.css similarity index 100% rename from build/backloggery.css rename to gamebuild/backloggery.css diff --git a/build/nowplaying.png b/gamebuild/nowplaying.png similarity index 100% rename from build/nowplaying.png rename to gamebuild/nowplaying.png diff --git a/build/paused.png b/gamebuild/paused.png similarity index 100% rename from build/paused.png rename to gamebuild/paused.png diff --git a/skeleton.py b/gameskel.py similarity index 54% rename from skeleton.py rename to gameskel.py index ebf5ffc..554385d 100644 --- a/skeleton.py +++ b/gameskel.py @@ -3,31 +3,31 @@ import variables from pathlib import Path """ -Generate the skeleton for an HTML page. +Generate the skeleton for a games backlog HTML page. """ home = str(Path.home()) def headerwrite(output,section,local=False): header = open(output, "a") - rgb = colorsys.hls_to_rgb((variables.hue)/360,0.3,0.45) + rgb = colorsys.hls_to_rgb((variables.gamehue)/360,0.3,0.45) hexstring = "" for element in rgb: hexstring += str(hex(int(element * 255)))[2:] - header.write("\n\n \n \n \n \n Static backlog\n \n \n\n \n \n \n \n Static backlog\n \n \n \n \n
\n
\n \n
\n
\n
\n") + header.write(variables.gameserverpath) + header.write("backloggery.css\" rel=\"stylesheet\">\n \n \n
\n
\n \n
\n
\n
\n") header.write(" Backlog\n Library\n History\n
\n") header.close() @@ -56,5 +56,5 @@ def footerwrite(output): footer.close() if __name__ == "__main__": - headerwrite("build/backlog/index.html","backlog",True) + headerwrite("gamebuild/backlog/index.html","backlog",True) footerwrite("test.html") diff --git a/gamesort.py b/gamesort.py index 9b65a95..866a5e4 100644 --- a/gamesort.py +++ b/gamesort.py @@ -8,7 +8,7 @@ Load in the list of games from a set of .org files. thisyear = datetime.now().strftime("%Y") -year = variables.startyear - 1 +year = variables.gamestartyear - 1 concernedfiles = [] diff --git a/generate.py b/generate.py deleted file mode 100644 index 6e1b988..0000000 --- a/generate.py +++ /dev/null @@ -1,26 +0,0 @@ -import sys - -import backlog -import library -import sublibrary -import history - -try: - if sys.argv[1] == "local": - local = True - else: - local = False -except: - local = False - -if __name__ == "__main__": - if local == True: - backlog.backlog(True) - library.library(True) - sublibrary.sublibrary(True) - history.history(True) - else: - backlog.backlog() - library.library() - sublibrary.sublibrary() - history.history() diff --git a/generategames.py b/generategames.py new file mode 100644 index 0000000..c9f4fab --- /dev/null +++ b/generategames.py @@ -0,0 +1,26 @@ +import sys,variables + +try: + if sys.argv[1] == "local": + local = True + else: + local = False +except: + local = False + +if variables.trackgames == True: + import backlog + import library + import sublibrary + import history + if __name__ == "__main__": + if local == True: + backlog.backlog(True) + library.library(True) + sublibrary.sublibrary(True) + history.history(True) + else: + backlog.backlog() + library.library() + sublibrary.sublibrary() + history.history() diff --git a/history.py b/history.py index 34dd5d3..9de7fbf 100644 --- a/history.py +++ b/history.py @@ -1,5 +1,5 @@ import os -import gamesort,skeleton,variables +import gamesort,gameskel,variables from datetime import datetime,timedelta """ @@ -8,24 +8,24 @@ Generates history page and RSS feed def history(local=False): # delete existing files - if not os.path.isdir("build/history"): - os.mkdir("build/history") - if os.path.exists("build/history/index.html"): - os.remove("build/history/index.html") - if os.path.exists("build/feed.xml"): - os.remove("build/feed.xml") + if not os.path.isdir("gamebuild/history"): + os.mkdir("gamebuild/history") + if os.path.exists("gamebuild/history/index.html"): + os.remove("gamebuild/history/index.html") + if os.path.exists("gamebuild/feed.xml"): + os.remove("gamebuild/feed.xml") # write header - skeleton.headerwrite("build/history/index.html","history",local) - output = "build/history/index.html" + gameskel.headerwrite("gamebuild/history/index.html","history",local) + output = "gamebuild/history/index.html" filewrite = open(output, "a") filewrite.write("
\n
\n") - feedwrite = open("build/feed.xml", "a") - feedwrite.write("\n\n \n \n Static backlog\n " + variables.domain + variables.serverpath + "backlog\n Feed for gaming updates\n en-gb") + feedwrite = open("gamebuild/feed.xml", "a") + feedwrite.write("\n\n \n \n Static backlog\n " + variables.domain + variables.gameserverpath + "backlog\n Feed for gaming updates\n en-gb") theyear = int(gamesort.thisyear) - while theyear >= variables.startyear: + while theyear >= variables.gamestartyear: yearlist = [] enddate = datetime.strptime((str(theyear) + "-12-31"),"%Y-%m-%d") startdate = datetime.strptime((str(theyear) + "-01-01"),"%Y-%m-%d") @@ -65,7 +65,7 @@ def history(local=False): else: filewrite.write(event["action"]) filewrite.write("\">
\n
\n
" + event["name"] + "\n (" + event["console"] + ")\n
\n
\n
\n") - feedwrite.write(" \n " + event["action"] + " " + event["name"] + " (" + event["console"] + ")\n " + event["date"].strftime("%a, %-d %b %Y") + " 00:00:00 GMT\n " + variables.domain + variables.serverpath + "history\n " + event["action"] + "-" + event["name"].replace(" ","-") + "-" + event["console"] + "\n " + event["action"] + " " + event["name"] + " (" + event["console"] + ")\n \n") + feedwrite.write(" \n " + event["action"] + " " + event["name"] + " (" + event["console"] + ")\n " + event["date"].strftime("%a, %-d %b %Y") + " 00:00:00 GMT\n " + variables.domain + variables.gameserverpath + "history\n " + event["action"] + "-" + event["name"].replace(" ","-") + "-" + event["console"] + "\n " + event["action"] + " " + event["name"] + " (" + event["console"] + ")\n \n") checkdate = event["date"] theyear -= 1 @@ -162,7 +162,7 @@ def history(local=False): filewrite.write("
\n
\n") filewrite.close() - skeleton.footerwrite("build/history/index.html") + gameskel.footerwrite("gamebuild/history/index.html") if __name__ == "__main__": history(True) diff --git a/init.py b/init.py index c081560..4831ea9 100644 --- a/init.py +++ b/init.py @@ -2,4 +2,9 @@ import variables script = open("build.sh", "a") -script.write("#!/usr/bin/env bash\npython3 generate.py\nrclone copy build " + variables.rclonesiteroot + variables.serverpath + " -P") +script.write("#!/usr/bin/env bash\n") + +if variables.trackgames == True: + script.write("python3 generategames.py\nrclone copy gamebuild " + variables.rclonesiteroot + variables.serverpath + " -P") + +script.close() diff --git a/library.py b/library.py index 4cf1f3b..d808cbe 100644 --- a/library.py +++ b/library.py @@ -7,47 +7,47 @@ Generates library page def library(local=False): # delete existing file - if not os.path.isdir("build/library"): - os.mkdir("build/library") - if os.path.exists("build/library/index.html"): - os.remove("build/library/index.html") + 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("build/library/index.html","library",local) - output = "build/library/index.html" + skeleton.headerwrite("gamebuild/library/index.html","library",local) + output = "gamebuild/library/index.html" filewrite = open(output, "a") filewrite.write("
\n
\n
\n
\n Total Found " + str(gamesort.total(gamesort.games)) + "\n
\n") if gamesort.unplayed(gamesort.games) > 0: filewrite.write(" \n") if gamesort.unfinished(gamesort.games) > 0: filewrite.write(" \n") if gamesort.beaten(gamesort.games) > 0: filewrite.write(" \n") if gamesort.completed(gamesort.games) > 0: filewrite.write(" \n") if gamesort.endless(gamesort.games) > 0: filewrite.write(" \n") @@ -59,7 +59,7 @@ def library(local=False): filewrite.write(cardstring.playcard(game,local)) filewrite.close() - skeleton.footerwrite("build/library/index.html") + skeleton.footerwrite("gamebuild/library/index.html") if __name__ == "__main__": library(True) diff --git a/sublibrary.py b/sublibrary.py index 7fcaeb6..defffa4 100644 --- a/sublibrary.py +++ b/sublibrary.py @@ -1,5 +1,5 @@ import os -import cardstring,gamesort,skeleton,variables +import cardstring,gamesort,gameskel,variables from pathlib import Path """ @@ -89,78 +89,78 @@ def sublibrary(local=False): pass except: filterlist.append(game) - if not os.path.isdir("build/library/" + console["shortname"].lower() + "-" + status): + if not os.path.isdir("gamebuild/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") + os.mkdir("gamebuild/library/" + console["shortname"].lower() + "-" + status) + if os.path.exists("gamebuild/library/" + console["shortname"].lower() + "-" + status + "/index.html"): + os.remove("gamebuild/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" + gameskel.headerwrite(("gamebuild/library/" + console["shortname"].lower() + "-" + status + "/index.html"),"sublibrary",local) + output = "gamebuild/library/" + console["shortname"].lower() + "-" + status + "/index.html" filewrite = open(output, "a") filewrite.write("
\n
\n
\n
Filtered by\n") if console["shortname"] != "all": filewrite.write(" 1 Platformx\n") if status != "all": filewrite.write(" 1 Statusx\n") filewrite.write("
\n
\n
\n Total Found " + str(gamesort.total(filterlist)) + "\n
\n") if gamesort.unplayed(filterlist) > 0: filewrite.write(" \n") if gamesort.unfinished(filterlist) > 0: filewrite.write(" \n") if gamesort.beaten(filterlist) > 0: filewrite.write(" \n") if gamesort.completed(filterlist) > 0: filewrite.write(" \n") if gamesort.endless(filterlist) > 0: filewrite.write(" \n") filewrite.write("
\n
\n") @@ -170,7 +170,7 @@ def sublibrary(local=False): filewrite.write(cardstring.playcard(game,local)) filewrite.close() - skeleton.footerwrite("build/library/" + console["shortname"].lower() + "-" + status + "/index.html") + gameskel.footerwrite("gamebuild/library/" + console["shortname"].lower() + "-" + status + "/index.html") if __name__ == "__main__": sublibrary(True) diff --git a/variables-template.py b/variables-template.py index 2e7f41f..04be322 100644 --- a/variables-template.py +++ b/variables-template.py @@ -2,23 +2,29 @@ User-defined variables live here. """ -endlessgames = [] - orgpath = "" localpath = "" -serverpath = "" - domain = "" rclonesiteroot = "" -description = "" +""" +Games +""" + +trackgames = False -startyear = +gameserverpath = "" + +endlessgames = [] -hue = +gamedescription = "" + +gamestartyear = 0 + +gamehue = 0 consoles = [{"code":"ps5","name":"PlayStation 5","shortname":"PS5","img":"PS5"}, {"code":"ps2","name":"PlayStation 2","shortname":"PS2","img":"PS2"}, @@ -28,3 +34,11 @@ consoles = [{"code":"ps5","name":"PlayStation 5","shortname":"PS5","img":"PS5"}, {"code":"nintendo 3ds","name":"Nintendo 3DS","shortname":"3DS","img":"3DS"}, {"code":"nintendo switch","name":"Nintendo Switch","shortname":"Switch","img":"Switch"}, {"code":"pc","name":"PC","shortname":"PC","img":"PC"}] + +""" +Places +""" + +trackplaces = False + +placeserverpath = ""