diff --git a/.gitignore b/.gitignore index 0e9d6bf..b09ed1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ __pycache__/ build.sh -build/* -!build/*.css -!build/*.png +gamebuild/* +!gamebuild/*.css +!gamebuild/*.png +placebuild/* +!placebuild/.gitkeep +recordbuild/index.html variables.py \ No newline at end of file diff --git a/README.org b/README.org index 390679a..a920785 100644 --- a/README.org +++ b/README.org @@ -1,28 +1,67 @@ #+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 -- =python3= - =orgparse= (install via pip) +- =python3= - =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 =build/backloggery.css=. Alternatively, you can load the fonts remotely and adjust the page head HTML generated by =skeleton.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 =gamebuild/backloggery.css=. Alternatively, you can load the fonts remotely and adjust the page head HTML generated by =gameskel.py=. *** Setting the variables -Rename =variables-template.py= to =variables.py= and edit: +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)= -- =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) -- =startyear=: year from which to begin tracking (an integer) -- =hue=: theme colour expressed as a hue from 0 to 360 +- =gamestartyear=: year from which to begin tracking (an integer) +- =gamehue=: 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 +** 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) - 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. +* Building - 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/demo.org b/demo.org index 17172c5..a06c603 100644 --- a/demo.org +++ b/demo.org @@ -12,3 +12,7 @@ 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/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 98% rename from build/backloggery.css rename to gamebuild/backloggery.css index 9adb689..38e68ca 100644 --- a/build/backloggery.css +++ b/gamebuild/backloggery.css @@ -239,7 +239,9 @@ svg text { width:100% } - +.unibar a { + color: inherit; +} .Added,.unplayed,.Unplayed { background-color:var(--unplayed-color)!important; @@ -828,14 +830,27 @@ 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); + 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-radius:.5rem; margin:.25rem; max-width:8rem; -opacity:.8; -padding:.4rem 1rem .5rem} + 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; +} .library .filters .item:hover { opacity:1} 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/generateplaces.py b/generateplaces.py new file mode 100644 index 0000000..a9972a8 --- /dev/null +++ b/generateplaces.py @@ -0,0 +1,121 @@ +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 new file mode 100644 index 0000000..56c88d4 --- /dev/null +++ b/generaterecords.py @@ -0,0 +1,88 @@ +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 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..580e0dc 100644 --- a/init.py +++ b/init.py @@ -1,5 +1,16 @@ import variables -script = open("build.sh", "a") +script = open("build.sh", "w") -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.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() diff --git a/library.py b/library.py index 31f86a7..336f53e 100644 --- a/library.py +++ b/library.py @@ -1,5 +1,5 @@ import os -import cardstring,gamesort,skeleton +import cardstring,gamesort,gameskel,variables """ Generates library page @@ -7,25 +7,50 @@ 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" + gameskel.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("
" + str(gamesort.unplayed(gamesort.games)) + "
\n") + filewrite.write(" \n") if gamesort.unfinished(gamesort.games) > 0: - filewrite.write("
" + str(gamesort.unfinished(gamesort.games)) + "
\n") + filewrite.write(" \n") if gamesort.beaten(gamesort.games) > 0: - filewrite.write("
" + str(gamesort.beaten(gamesort.games)) + "
\n") + filewrite.write(" \n") if gamesort.completed(gamesort.games) > 0: - filewrite.write("
" + str(gamesort.completed(gamesort.games)) + "
\n") + filewrite.write(" \n") if gamesort.endless(gamesort.games) > 0: - filewrite.write("
" + str(gamesort.endless(gamesort.games)) + "
\n") + filewrite.write(" \n") filewrite.write("
\n
\n") newgames = sorted(gamesort.games,key=lambda d: d["id"]) @@ -34,7 +59,7 @@ def library(local=False): filewrite.write(cardstring.playcard(game,local)) filewrite.close() - skeleton.footerwrite("build/library/index.html") + gameskel.footerwrite("gamebuild/library/index.html") if __name__ == "__main__": library(True) diff --git a/placebuild/.gitkeep b/placebuild/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/recordbuild/large.png b/recordbuild/large.png new file mode 100644 index 0000000..d57e8c2 Binary files /dev/null and b/recordbuild/large.png differ diff --git a/recordbuild/small.png b/recordbuild/small.png new file mode 100644 index 0000000..b470e62 Binary files /dev/null and b/recordbuild/small.png differ diff --git a/sublibrary.py b/sublibrary.py index ad5564f..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,54 +89,79 @@ 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 Platform\n") + filewrite.write(variables.gameserverpath + "library/all-" + status) + filewrite.write("\">1 Platformx\n") if status != "all": filewrite.write(" 1 Status\n") + filewrite.write(variables.gameserverpath + "library/" + console["shortname"].lower() + "-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("
" + str(gamesort.unplayed(filterlist)) + "
\n") + filewrite.write(" \n") if gamesort.unfinished(filterlist) > 0: - filewrite.write("
" + str(gamesort.unfinished(filterlist)) + "
\n") + filewrite.write(" \n") if gamesort.beaten(filterlist) > 0: - filewrite.write("
" + str(gamesort.beaten(filterlist)) + "
\n") + filewrite.write(" \n") if gamesort.completed(filterlist) > 0: - filewrite.write("
" + str(gamesort.completed(filterlist)) + "
\n") + filewrite.write(" \n") if gamesort.endless(filterlist) > 0: - filewrite.write("
" + str(gamesort.endless(filterlist)) + "
\n") + filewrite.write(" \n") filewrite.write("
\n
\n") newgames = sorted(filterlist,key=lambda d: d["id"]) @@ -145,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..8016e83 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 +""" -startyear = +trackgames = False -hue = +gameserverpath = "" + +endlessgames = [] + +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,31 @@ 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 = ""