diff --git a/.gitignore b/.gitignore index b09ed1f..0e9d6bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,6 @@ __pycache__/ build.sh -gamebuild/* -!gamebuild/*.css -!gamebuild/*.png -placebuild/* -!placebuild/.gitkeep -recordbuild/index.html +build/* +!build/*.css +!build/*.png variables.py \ No newline at end of file diff --git a/README.org b/README.org index a920785..390679a 100644 --- a/README.org +++ b/README.org @@ -1,67 +1,28 @@ #+TITLE: Trackers -* About -The scripts in this repository build static webpages based on information from two sources: -- a structured set of =.org= files; -- APIs of selected third-party websites (so far: Discogs). -These pages can be used as a replacement for third-party services e.g. Backloggery. * Dependencies -- =orgparse= (install via pip) - =python3= +- =orgparse= (install via pip) - =rclone= (for syncing to the server) -- =geopy= if you are tracking places visited (install via pip) -- =python3-discogs-client= if you are displaying a record collection (install via pip) -* General setup -** Structure of the .org files -See =demo.org= for an example. -** Setting the variables -Copy =variables-template.py= to =variables.py= and edit: -- =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 -- =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 =gamebuild/backloggery.css=. Alternatively, you can load the fonts remotely and adjust the page head HTML generated by =gameskel.py=. +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 +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 - =description=: content for the “about” section (can include HTML tags) -- =gamestartyear=: year from which to begin tracking (an integer) -- =gamehue=: theme colour expressed as a hue from 0 to 360 +- =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) -** Testing -- Run =python3 generategames.py local= to build in =gamebuild=. -* Tracking places visited using Leaflet -** Setup -Upload a CSS file to the server if necessary. Most CSS is set by Leaflet. -*** Setting the variables -In =variables.py=, edit: -- =trackplaces=: set to =True= -- =placeserverpath=: path to directory on the server where files will be uploaded, including trailing slash -- =placestartyear=: year from which to begin tracking (an integer) -- =placecss=: location of the CSS file you wish to apply, relative to the site root -** Testing -- Run =python3 generateplaces.py local= to build in =placebuild=. (This may take some time.) -- Check whether places are displayed accurately in the output file. If not, add regions/countries to disambiguate any incorrectly displayed places to the =disambig= dictionary in =variables.py= (see examples). -* Displaying a record collection (taking data from Discogs) -** Setup -- Upload a CSS file to the server for styling fonts etc; most CSS is set inline. -- Get a Discogs API token [[https://www.discogs.com/settings/developers][here]]. -*** Setting the variables -In =variables.py=, edit: -- =trackrecords=: set to =True= -- =recordserverpath=: path to directory on the server where files will be uploaded, including trailing slash -- =recordcss=: location of the CSS file you wish to apply, relative to the site root -- =discogstoken=: the API token you generated -- =discogsuser=: your Discogs username -** Testing -- Run =python3 generaterecords.py local= to build in =recordbuild=. -* First run (or if adding any new trackers) +*** The rest - Run =python3 init.py= and then =chmod +x build.sh=. -- Create directories on the server corresponding to any =*serverpath= variables you have set. -* Building +- Create the directory on the server. +** Generating the files +- Run =python3 generate.py local= to build in the local =build= directory. - Run =./build.sh= to build and upload to the server. diff --git a/backlog.py b/backlog.py index 05bd707..636f2a3 100644 --- a/backlog.py +++ b/backlog.py @@ -1,5 +1,5 @@ import os -import cardstring,gamesort,gameskel,variables +import cardstring,gamesort,skeleton,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("gamebuild/backlog"): - os.mkdir("gamebuild/backlog") - if os.path.exists("gamebuild/backlog/index.html"): - os.remove("gamebuild/backlog/index.html") + 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 - gameskel.headerwrite("gamebuild/backlog/index.html","backlog",local) - output = "gamebuild/backlog/index.html" + 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 = [] @@ -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() - gameskel.footerwrite("gamebuild/backlog/index.html") + skeleton.footerwrite("build/backlog/index.html") if __name__ == "__main__": backlog(True) diff --git a/gamebuild/360.png b/build/360.png similarity index 100% rename from gamebuild/360.png rename to build/360.png diff --git a/gamebuild/3DS.png b/build/3DS.png similarity index 100% rename from gamebuild/3DS.png rename to build/3DS.png diff --git a/gamebuild/B.png b/build/B.png similarity index 100% rename from gamebuild/B.png rename to build/B.png diff --git a/gamebuild/C.png b/build/C.png similarity index 100% rename from gamebuild/C.png rename to build/C.png diff --git a/gamebuild/E.png b/build/E.png similarity index 100% rename from gamebuild/E.png rename to build/E.png diff --git a/gamebuild/NDS.png b/build/NDS.png similarity index 100% rename from gamebuild/NDS.png rename to build/NDS.png diff --git a/gamebuild/PC.png b/build/PC.png similarity index 100% rename from gamebuild/PC.png rename to build/PC.png diff --git a/gamebuild/PS2.png b/build/PS2.png similarity index 100% rename from gamebuild/PS2.png rename to build/PS2.png diff --git a/gamebuild/PS3.png b/build/PS3.png similarity index 100% rename from gamebuild/PS3.png rename to build/PS3.png diff --git a/gamebuild/PS5.png b/build/PS5.png similarity index 100% rename from gamebuild/PS5.png rename to build/PS5.png diff --git a/gamebuild/Switch.png b/build/Switch.png similarity index 100% rename from gamebuild/Switch.png rename to build/Switch.png diff --git a/gamebuild/UF.png b/build/UF.png similarity index 100% rename from gamebuild/UF.png rename to build/UF.png diff --git a/gamebuild/UP.png b/build/UP.png similarity index 100% rename from gamebuild/UP.png rename to build/UP.png diff --git a/gamebuild/backloggery.css b/build/backloggery.css similarity index 98% rename from gamebuild/backloggery.css rename to build/backloggery.css index 38e68ca..9adb689 100644 --- a/gamebuild/backloggery.css +++ b/build/backloggery.css @@ -239,9 +239,7 @@ svg text { width:100% } -.unibar a { - color: inherit; -} + .Added,.unplayed,.Unplayed { background-color:var(--unplayed-color)!important; @@ -830,27 +828,14 @@ width:95%} opacity:1} */ .library .filters .item { - border:2px solid rgba(0,0,0,.5); - background-color:var(--active-secondary); - color:var(--active-secondary-text); - display: inline-block; - font-size: 0.8rem; +border:2px solid rgba(0,0,0,.5); +background-color:var(--active-secondary); +color:var(--active-secondary-text); border-radius:.5rem; margin:.25rem; max-width:8rem; - opacity:.8; - position: relative; - padding:.45rem 2rem .5rem 1rem; - white-space: nowrap; -} - -.library .filters .item .filter_clear { - border-radius: .5rem; - padding: .425rem .5rem .475rem; - position: absolute; - right: 0; - top: 0; -} +opacity:.8; +padding:.4rem 1rem .5rem} .library .filters .item:hover { opacity:1} diff --git a/gamebuild/nowplaying.png b/build/nowplaying.png similarity index 100% rename from gamebuild/nowplaying.png rename to build/nowplaying.png diff --git a/gamebuild/paused.png b/build/paused.png similarity index 100% rename from gamebuild/paused.png rename to build/paused.png diff --git a/cardstring.py b/cardstring.py index 938a0be..56f5da1 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/demo.org b/demo.org index a06c603..17172c5 100644 --- a/demo.org +++ b/demo.org @@ -12,7 +12,3 @@ Notes about the games can be stored under each heading. *** demo game 3 (pc) ** completed *** demo game 4 (nintendo ds) -* places -** visited -*** demo place 1 -*** demo place 2 <2024-02-17 Sat>--<2024-02-18 Sun> diff --git a/gamesort.py b/gamesort.py index 866a5e4..9b65a95 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.gamestartyear - 1 +year = variables.startyear - 1 concernedfiles = [] diff --git a/generate.py b/generate.py new file mode 100644 index 0000000..6e1b988 --- /dev/null +++ b/generate.py @@ -0,0 +1,26 @@ +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 deleted file mode 100644 index c9f4fab..0000000 --- a/generategames.py +++ /dev/null @@ -1,26 +0,0 @@ -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/generateplaces.py b/generateplaces.py deleted file mode 100644 index a9972a8..0000000 --- a/generateplaces.py +++ /dev/null @@ -1,121 +0,0 @@ -import orgparse,os,re,sys,variables -import time -from datetime import datetime -from geopy.geocoders import Nominatim - -try: - if sys.argv[1] == "local": - local = True - else: - local = False -except: - local = False - -if variables.trackplaces == True: - - thisyear = datetime.now().strftime("%Y") - - year = variables.placestartyear - - concernedfiles = [] - - geo = Nominatim(user_agent="python3") - - while year < int(thisyear) + 1: - month = 0 - while month < 13: - if month < 10: - strmonth = "0" + str(month) - else: - strmonth = str(month) - recdir = str(year) + "/" + strmonth + "/" - fullpath = variables.orgpath + recdir - if os.path.exists(fullpath): - for file in sorted(os.listdir(fullpath)): - filename = fullpath + str(file) - if filename.endswith(".org"): - concernedfiles.append(filename) - month = month + 1 - year = year + 1 - - places = [] - placenames = [] - - for file in concernedfiles: - filedate = file[-14:-4] - dateobj = datetime.strptime(filedate,"%Y-%m-%d") - parsefile = orgparse.load(file) - try: - for node in parsefile.children: - if node.heading == "places": - for action in node.children: - if action.heading == "visited": - for place in action.children: - placename = re.sub(" <.*>","",re.sub("<.*> ","",place.heading)) - if placename not in placenames: - status = "new" - placenames.append(placename) - else: - status = "existing" - if "<" in place.heading: - dates = re.sub(" [A-Z][a-z][a-z]","",re.sub("--"," to ",re.sub(">","",re.sub("<","",(re.findall("\<.*\>",place.heading)[0]))))) - else: - dates = filedate - if status == "new": - try: - lookup = placename + ", " + variables.disambig[placename] - except: - lookup = placename - thedict = {"name":placename,"dates":[dates],"lookup":lookup} - places.append(thedict) - else: - twodict = {"name":placename,"dates":[dates]} - for origplace in places: - if twodict["name"] == origplace["name"]: - origplace["dates"].extend(twodict["dates"]) - except: - pass - - for place in places: - place["dates"] = list(dict.fromkeys(place["dates"])) - - theplaces = sorted(places,key=lambda d: d["name"]) - - for place in theplaces: - print("Fetching " + place["name"]) - place["lat"] = None - while place["lat"] == None: - try: - place["lat"] = geo.geocode(place["lookup"]).latitude - except: - time.sleep(3) - continue - place["long"] = None - while place["long"] == None: - try: - place["long"] = geo.geocode(place["lookup"]).longitude - except: - time.sleep(3) - continue - - alllats = [] - alllongs = [] - for place in theplaces: - if place["lat"] != 0: - alllats.append(place["lat"]) - if place["long"] != 0: - alllongs.append(place["long"]) - avglat = (max(alllats) + min(alllats))/2 - avglong = (max(alllongs) + min(alllongs))/2 - writefile = open("placebuild/index.html","w") - writefile.write("\n\n \n \n \n \n Map\n \n \n \n \n \n \n
\n \n \n") diff --git a/generaterecords.py b/generaterecords.py deleted file mode 100644 index 56c88d4..0000000 --- a/generaterecords.py +++ /dev/null @@ -1,88 +0,0 @@ -import discogs_client,re,time,variables -d = discogs_client.Client("Python/1.0",user_token=variables.discogstoken) - -user = d.user(variables.discogsuser) - -try: - if sys.argv[1] == "local": - local = True - else: - local = False -except: - local = False - -if variables.trackrecords == True: - - records = [] - - thenumber = 1 - maxno = len(user.collection_folders[0].releases) - - def typography(thestring): - return re.sub(" / ","/",re.sub(" \(.*\)","",re.sub(" - "," – ",re.sub(" "," ",re.sub("\.\.\."," …",re.sub("'","’",re.sub(" = .*","",thestring))))))) - - print("Fetching records from Discogs") - - for item in user.collection_folders[0].releases: - print("Fetching " + str(thenumber) + " of " + str(maxno)) - theitem = {} - theitem["artist"] = typography(item.release.artists[0].name) - theitem["title"] = typography(item.release.title) - try: - if "LP" in item.release.formats[0]["descriptions"] or "12\"" in item.release.formats[0]["descriptions"]: - theitem["format"] = "large" - else: - theitem["format"] = "small" - except: - theitem["format"] = "small" - try: - theitem["img"] = item.release.images[0]["uri"] - except: - pass - records.append(theitem) - thenumber += 1 - time.sleep(1) # only allowed 1 request per second - - records = sorted(records, key=lambda d: d["title"]) - records = sorted(records, key=lambda d: d["artist"]) - - smalls = [] - larges = [] - for record in records: - if record["format"] == "large": - larges.append(record) - else: - smalls.append(record) - - def recordwrite(record): - recordstring = "
\n \n
\n

" + record["artist"] + "

" + record["title"] + "

\n
\n
\n" - return recordstring - - writefile = open("recordbuild/index.html","w") - - writefile.write("\n\n \n \n \n Record collection\n \n \n \n

Record collection

\n
\n") - - for record in smalls: - writefile.write(recordwrite(record)) - - for record in larges: - writefile.write(recordwrite(record)) - - writefile.write("
\n

Generic disc icons by popo2021 and Dinosoft Labs on Flaticon.

\n \n\n") - - writefile.close() diff --git a/history.py b/history.py index 9de7fbf..34dd5d3 100644 --- a/history.py +++ b/history.py @@ -1,5 +1,5 @@ import os -import gamesort,gameskel,variables +import gamesort,skeleton,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("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") + 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") # write header - gameskel.headerwrite("gamebuild/history/index.html","history",local) - output = "gamebuild/history/index.html" + skeleton.headerwrite("build/history/index.html","history",local) + output = "build/history/index.html" filewrite = open(output, "a") filewrite.write("

\n
\n") - 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") + 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") theyear = int(gamesort.thisyear) - while theyear >= variables.gamestartyear: + while theyear >= variables.startyear: 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.gameserverpath + "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.serverpath + "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() - gameskel.footerwrite("gamebuild/history/index.html") + skeleton.footerwrite("build/history/index.html") if __name__ == "__main__": history(True) diff --git a/init.py b/init.py index 580e0dc..c081560 100644 --- a/init.py +++ b/init.py @@ -1,16 +1,5 @@ import variables -script = open("build.sh", "w") +script = open("build.sh", "a") -script.write("#!/usr/bin/env bash\n") - -if variables.trackgames == True: - script.write("python3 generategames.py\nrclone copy gamebuild " + variables.rclonesiteroot + variables.gameserverpath + " -P\n") - -if variables.trackplaces == True: - script.write("python3 generateplaces.py\nrclone copy placebuild " + variables.rclonesiteroot + variables.placeserverpath + " -P\n") - -if variables.trackrecords == True: - script.write("python3 generaterecords.py\nrclone copy recordbuild " + variables.rclonesiteroot + variables.recordserverpath + " -P\n") - -script.close() +script.write("#!/usr/bin/env bash\npython3 generate.py\nrclone copy build " + variables.rclonesiteroot + variables.serverpath + " -P") diff --git a/library.py b/library.py index 336f53e..31f86a7 100644 --- a/library.py +++ b/library.py @@ -1,5 +1,5 @@ import os -import cardstring,gamesort,gameskel,variables +import cardstring,gamesort,skeleton """ Generates library page @@ -7,50 +7,25 @@ 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") + 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") # write header - gameskel.headerwrite("gamebuild/library/index.html","library",local) - output = "gamebuild/library/index.html" + skeleton.headerwrite("build/library/index.html","library",local) + output = "build/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") + filewrite.write("
" + str(gamesort.unplayed(gamesort.games)) + "
\n") if gamesort.unfinished(gamesort.games) > 0: - filewrite.write(" \n") + filewrite.write("
" + str(gamesort.unfinished(gamesort.games)) + "
\n") if gamesort.beaten(gamesort.games) > 0: - filewrite.write(" \n") + filewrite.write("
" + str(gamesort.beaten(gamesort.games)) + "
\n") if gamesort.completed(gamesort.games) > 0: - filewrite.write(" \n") + filewrite.write("
" + str(gamesort.completed(gamesort.games)) + "
\n") if gamesort.endless(gamesort.games) > 0: - filewrite.write(" \n") + filewrite.write("
" + str(gamesort.endless(gamesort.games)) + "
\n") filewrite.write("
\n
\n") newgames = sorted(gamesort.games,key=lambda d: d["id"]) @@ -59,7 +34,7 @@ def library(local=False): filewrite.write(cardstring.playcard(game,local)) filewrite.close() - gameskel.footerwrite("gamebuild/library/index.html") + skeleton.footerwrite("build/library/index.html") if __name__ == "__main__": library(True) diff --git a/placebuild/.gitkeep b/placebuild/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/recordbuild/large.png b/recordbuild/large.png deleted file mode 100644 index d57e8c2..0000000 Binary files a/recordbuild/large.png and /dev/null differ diff --git a/recordbuild/small.png b/recordbuild/small.png deleted file mode 100644 index b470e62..0000000 Binary files a/recordbuild/small.png and /dev/null differ diff --git a/gameskel.py b/skeleton.py similarity index 54% rename from gameskel.py rename to skeleton.py index 554385d..ebf5ffc 100644 --- a/gameskel.py +++ b/skeleton.py @@ -3,31 +3,31 @@ import variables from pathlib import Path """ -Generate the skeleton for a games backlog HTML page. +Generate the skeleton for an HTML page. """ home = str(Path.home()) def headerwrite(output,section,local=False): header = open(output, "a") - rgb = colorsys.hls_to_rgb((variables.gamehue)/360,0.3,0.45) + rgb = colorsys.hls_to_rgb((variables.hue)/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.serverpath) + 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("gamebuild/backlog/index.html","backlog",True) + headerwrite("build/backlog/index.html","backlog",True) footerwrite("test.html") diff --git a/sublibrary.py b/sublibrary.py index defffa4..ad5564f 100644 --- a/sublibrary.py +++ b/sublibrary.py @@ -1,5 +1,5 @@ import os -import cardstring,gamesort,gameskel,variables +import cardstring,gamesort,skeleton,variables from pathlib import Path """ @@ -89,79 +89,54 @@ def sublibrary(local=False): pass except: filterlist.append(game) - if not os.path.isdir("gamebuild/library/" + console["shortname"].lower() + "-" + status): + if not os.path.isdir("build/library/" + console["shortname"].lower() + "-" + status): if len(filterlist) > 0: - 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") + 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: - gameskel.headerwrite(("gamebuild/library/" + console["shortname"].lower() + "-" + status + "/index.html"),"sublibrary",local) - output = "gamebuild/library/" + console["shortname"].lower() + "-" + status + "/index.html" + 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("
\n
\n
\n
Filtered by\n") if console["shortname"] != "all": filewrite.write(" 1 Platformx\n") + filewrite.write(variables.serverpath + "library/all-" + status) + filewrite.write("\">1 Platform\n") if status != "all": filewrite.write(" 1 Statusx\n") + filewrite.write(variables.serverpath + "library/" + console["shortname"].lower() + "-all") + filewrite.write("\">1 Status\n") filewrite.write("
\n
\n
\n Total Found " + str(gamesort.total(filterlist)) + "\n
\n") if gamesort.unplayed(filterlist) > 0: - filewrite.write(" \n") + filewrite.write("
" + str(gamesort.unplayed(filterlist)) + "
\n") if gamesort.unfinished(filterlist) > 0: - filewrite.write(" \n") + filewrite.write("
" + str(gamesort.unfinished(filterlist)) + "
\n") if gamesort.beaten(filterlist) > 0: - filewrite.write(" \n") + filewrite.write("
" + str(gamesort.beaten(filterlist)) + "
\n") if gamesort.completed(filterlist) > 0: - filewrite.write(" \n") + filewrite.write("
" + str(gamesort.completed(filterlist)) + "
\n") if gamesort.endless(filterlist) > 0: - filewrite.write(" \n") + filewrite.write("
" + str(gamesort.endless(filterlist)) + "
\n") filewrite.write("
\n
\n") newgames = sorted(filterlist,key=lambda d: d["id"]) @@ -170,7 +145,7 @@ def sublibrary(local=False): filewrite.write(cardstring.playcard(game,local)) filewrite.close() - gameskel.footerwrite("gamebuild/library/" + console["shortname"].lower() + "-" + status + "/index.html") + skeleton.footerwrite("build/library/" + console["shortname"].lower() + "-" + status + "/index.html") if __name__ == "__main__": sublibrary(True) diff --git a/variables-template.py b/variables-template.py index 8016e83..2e7f41f 100644 --- a/variables-template.py +++ b/variables-template.py @@ -2,29 +2,23 @@ User-defined variables live here. """ +endlessgames = [] + orgpath = "" localpath = "" +serverpath = "" + domain = "" rclonesiteroot = "" -""" -Games -""" +description = "" -trackgames = False +startyear = -gameserverpath = "" - -endlessgames = [] - -gamedescription = "" - -gamestartyear = 0 - -gamehue = 0 +hue = consoles = [{"code":"ps5","name":"PlayStation 5","shortname":"PS5","img":"PS5"}, {"code":"ps2","name":"PlayStation 2","shortname":"PS2","img":"PS2"}, @@ -34,31 +28,3 @@ 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 = "" - -placestartyear = 0 - -placecss = "" - -# disambig = {"london":"england","belfast":"northern ireland"} - -""" -Records -""" - -trackrecords = False - -recordserverpath = "" - -recordcss = "" - -discogstoken = "" - -discogsuser = ""