From 6f84d8f4ae6c3dd2e11d9361dd10ea8c802d4959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Wed, 5 Jun 2024 21:05:43 +0100 Subject: [PATCH 01/10] Add meaningless close buttons to filters --- build/backloggery.css | 23 ++++++++++++++++++----- sublibrary.py | 4 ++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/build/backloggery.css b/build/backloggery.css index 9adb689..d905682 100644 --- a/build/backloggery.css +++ b/build/backloggery.css @@ -828,14 +828,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/sublibrary.py b/sublibrary.py index ad5564f..0c11a7f 100644 --- a/sublibrary.py +++ b/sublibrary.py @@ -112,7 +112,7 @@ def sublibrary(local=False): filewrite.write(variables.localpath + "build/library/all-" + status + "/index.html") else: filewrite.write(variables.serverpath + "library/all-" + status) - filewrite.write("\">1 Platform\n") + filewrite.write("\">1 Platformx\n") if status != "all": filewrite.write(" 1 Status\n") + 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") From 6a8a0c40e64ffb5b15c09a78953050deacda16f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Wed, 5 Jun 2024 21:30:43 +0100 Subject: [PATCH 02/10] Make the unibar clickable --- build/backloggery.css | 4 +++- library.py | 37 +++++++++++++++++++++++++++++++------ sublibrary.py | 35 ++++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/build/backloggery.css b/build/backloggery.css index d905682..38e68ca 100644 --- a/build/backloggery.css +++ b/build/backloggery.css @@ -239,7 +239,9 @@ svg text { width:100% } - +.unibar a { + color: inherit; +} .Added,.unplayed,.Unplayed { background-color:var(--unplayed-color)!important; diff --git a/library.py b/library.py index 31f86a7..4cf1f3b 100644 --- a/library.py +++ b/library.py @@ -1,5 +1,5 @@ import os -import cardstring,gamesort,skeleton +import cardstring,gamesort,skeleton,variables """ Generates library page @@ -17,15 +17,40 @@ def library(local=False): 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"]) diff --git a/sublibrary.py b/sublibrary.py index 0c11a7f..7fcaeb6 100644 --- a/sublibrary.py +++ b/sublibrary.py @@ -128,15 +128,40 @@ def sublibrary(local=False): 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"]) From 29ab288b652325d6aca77ecc1c9198980afe61df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Wed, 19 Jun 2024 15:52:15 +0100 Subject: [PATCH 03/10] Prepare for adding other trackers --- .gitignore | 6 +- README.org | 24 +++-- backlog.py | 136 +++++++++++++-------------- cardstring.py | 40 ++++---- {build => gamebuild}/360.png | Bin {build => gamebuild}/3DS.png | Bin {build => gamebuild}/B.png | Bin {build => gamebuild}/C.png | Bin {build => gamebuild}/E.png | Bin {build => gamebuild}/NDS.png | Bin {build => gamebuild}/PC.png | Bin {build => gamebuild}/PS2.png | Bin {build => gamebuild}/PS3.png | Bin {build => gamebuild}/PS5.png | Bin {build => gamebuild}/Switch.png | Bin {build => gamebuild}/UF.png | Bin {build => gamebuild}/UP.png | Bin {build => gamebuild}/backloggery.css | 0 {build => gamebuild}/nowplaying.png | Bin {build => gamebuild}/paused.png | Bin skeleton.py => gameskel.py | 26 ++--- gamesort.py | 2 +- generate.py | 26 ----- generategames.py | 26 +++++ history.py | 28 +++--- init.py | 7 +- library.py | 24 ++--- sublibrary.py | 52 +++++----- variables-template.py | 28 ++++-- 29 files changed, 224 insertions(+), 201 deletions(-) rename {build => gamebuild}/360.png (100%) rename {build => gamebuild}/3DS.png (100%) rename {build => gamebuild}/B.png (100%) rename {build => gamebuild}/C.png (100%) rename {build => gamebuild}/E.png (100%) rename {build => gamebuild}/NDS.png (100%) rename {build => gamebuild}/PC.png (100%) rename {build => gamebuild}/PS2.png (100%) rename {build => gamebuild}/PS3.png (100%) rename {build => gamebuild}/PS5.png (100%) rename {build => gamebuild}/Switch.png (100%) rename {build => gamebuild}/UF.png (100%) rename {build => gamebuild}/UP.png (100%) rename {build => gamebuild}/backloggery.css (100%) rename {build => gamebuild}/nowplaying.png (100%) rename {build => gamebuild}/paused.png (100%) rename skeleton.py => gameskel.py (54%) delete mode 100644 generate.py create mode 100644 generategames.py 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) +* General setup +*** Setting the variables +Rename =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=. *** 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 - =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 +""" -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,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 = "" From b90ff645d4208d6e8ad921e02ecdc7d9d0b85e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Wed, 19 Jun 2024 15:59:42 +0100 Subject: [PATCH 04/10] Corrections --- README.org | 5 +++-- init.py | 4 ++-- library.py | 16 ++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.org b/README.org index fec1a6b..64e3f1a 100644 --- a/README.org +++ b/README.org @@ -24,9 +24,10 @@ In =variables.py=, edit: - =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=. * First run - Run =python3 init.py= and then =chmod +x build.sh=. - 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. +* Building - Run =./build.sh= to build and upload to the server. diff --git a/init.py b/init.py index 4831ea9..4cd07c7 100644 --- a/init.py +++ b/init.py @@ -1,10 +1,10 @@ import variables -script = open("build.sh", "a") +script = open("build.sh", "w") 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.write("python3 generategames.py\nrclone copy gamebuild " + variables.rclonesiteroot + variables.gameserverpath + " -P") script.close() diff --git a/library.py b/library.py index d808cbe..336f53e 100644 --- a/library.py +++ b/library.py @@ -1,5 +1,5 @@ import os -import cardstring,gamesort,skeleton,variables +import cardstring,gamesort,gameskel,variables """ Generates library page @@ -12,7 +12,7 @@ def library(local=False): if os.path.exists("gamebuild/library/index.html"): os.remove("gamebuild/library/index.html") # write header - skeleton.headerwrite("gamebuild/library/index.html","library",local) + 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") @@ -21,35 +21,35 @@ def library(local=False): if local: filewrite.write(variables.localpath + "gamebuild/library/all-unplayed/index.html") else: - filewrite.write(variables.serverpath + "library/all-unplayed") + filewrite.write(variables.gameserverpath + "library/all-unplayed") filewrite.write("\">" + str(gamesort.unplayed(gamesort.games)) + "
\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") filewrite.write("
\n
\n") @@ -59,7 +59,7 @@ def library(local=False): filewrite.write(cardstring.playcard(game,local)) filewrite.close() - skeleton.footerwrite("gamebuild/library/index.html") + gameskel.footerwrite("gamebuild/library/index.html") if __name__ == "__main__": library(True) From fc286a07b5eb69928bbb5c3ced69f874b0835013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Wed, 19 Jun 2024 16:01:53 +0100 Subject: [PATCH 05/10] Further readme corrections --- README.org | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index 64e3f1a..ae773bb 100644 --- a/README.org +++ b/README.org @@ -21,13 +21,13 @@ In =variables.py=, edit: - =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 +- =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) ** Testing - Run =python3 generategames.py local= to build in =gamebuild=. * First run - Run =python3 init.py= and then =chmod +x build.sh=. -- Create directories on the server corresponding to any =*serverpath= variables you have set.. +- Create directories on the server corresponding to any =*serverpath= variables you have set. * Building - Run =./build.sh= to build and upload to the server. From 91c43c567137d03a7539f26ef3ecf7b40edab10b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Wed, 19 Jun 2024 16:26:09 +0100 Subject: [PATCH 06/10] Add place tracker --- .gitignore | 3 + README.org | 11 +++- demo.org | 4 ++ generateplaces.py | 132 ++++++++++++++++++++++++++++++++++++++++++ init.py | 5 +- placebuild/.gitkeep | 0 variables-template.py | 4 ++ 7 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 generateplaces.py create mode 100644 placebuild/.gitkeep diff --git a/.gitignore b/.gitignore index fc612dd..997bc77 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ build.sh gamebuild/* !gamebuild/*.css !gamebuild/*.png +placebuild/* +!placebuild/.gitkeep +places.py variables.py \ No newline at end of file diff --git a/README.org b/README.org index ae773bb..529af8c 100644 --- a/README.org +++ b/README.org @@ -26,7 +26,16 @@ In =variables.py=, edit: - =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=. -* First run +* 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, relative to the site root +* First run (or if adding any new trackers) - Run =python3 init.py= and then =chmod +x build.sh=. - Create directories on the server corresponding to any =*serverpath= variables you have set. * Building 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/generateplaces.py b/generateplaces.py new file mode 100644 index 0000000..78a5804 --- /dev/null +++ b/generateplaces.py @@ -0,0 +1,132 @@ +import orgparse,os,re,sys,variables +from datetime import datetime +import sys,variables + +try: + if sys.argv[1] == "local": + local = True + else: + local = False +except: + local = False + +if variables.trackgames == True: + + thisyear = datetime.now().strftime("%Y") + + year = variables.placestartyear + + concernedfiles = [] + + 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": + thedict = {"name":placename,"dates":[dates]} + 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"]) + + if os.path.isfile("places.py"): + import places + newplaces = [] + for place in theplaces: + for location in places.places: + if place["name"] == location["name"]: + break + else: + newplaces.append(place["name"]) + if len(newplaces) > 0: + with open("places.py","rb+") as editfile: + editfile.seek(-2, os.SEEK_END) + editfile.truncate() + appendfile = open("places.py","a") + for place in newplaces: + appendfile.write(",\n{\"name\":\"" + place + "\",\"lat\":0,\"long\":0}") + appendfile.write("]") + appendfile.close() + print("Add latitudes and longitudes in places.py before running again") + else: + alllats = [] + alllongs = [] + import places + for place in places.places: + 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") + else: + writefile = open("places.py","w") + writefile.write("places = [") + for place in theplaces: + writefile.write("{\"name\":\"" + place["name"] + "\",\"lat\":0,\"long\":0}") + if place != theplaces[-1]: + writefile.write(",\n") + writefile.write("]") + writefile.close() + print("Add latitudes and longitudes in places.py before running again") diff --git a/init.py b/init.py index 4cd07c7..b6e5e19 100644 --- a/init.py +++ b/init.py @@ -5,6 +5,9 @@ script = open("build.sh", "w") script.write("#!/usr/bin/env bash\n") if variables.trackgames == True: - script.write("python3 generategames.py\nrclone copy gamebuild " + variables.rclonesiteroot + variables.gameserverpath + " -P") + 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") script.close() diff --git a/placebuild/.gitkeep b/placebuild/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/variables-template.py b/variables-template.py index 04be322..360de53 100644 --- a/variables-template.py +++ b/variables-template.py @@ -42,3 +42,7 @@ Places trackplaces = False placeserverpath = "" + +placestartyear = 0 + +placecss = "" From ff76322a8237ac71f9bb16efdac2225515078d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Wed, 19 Jun 2024 16:34:40 +0100 Subject: [PATCH 07/10] Readme clarifications --- README.org | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index 529af8c..de4e97a 100644 --- a/README.org +++ b/README.org @@ -1,11 +1,15 @@ #+TITLE: Trackers +* About +The scripts in this repository take information from a structured set of =.org= files and use them to build static webpages that track various activities (so far, gaming and travelling). These pages can be used as a replacement for third-party services e.g. Backloggery. * Dependencies - =python3= - =orgparse= (install via pip) - =rclone= (for syncing to the server) * General setup -*** Setting the variables +** Structure of the .org files +See =demo.org= for an example. +** Setting the variables Rename =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 @@ -14,7 +18,7 @@ Rename =variables-template.py= to =variables.py= and edit: * 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 In =variables.py=, edit: - =trackgames=: set to =True= @@ -34,7 +38,10 @@ 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, relative to the site root +- =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=. +- If new places have been added since the last build, they will be added to =places.py= and the terminal will signal this. Add the latitude and longitude for these places in =places.py= before building again. * First run (or if adding any new trackers) - Run =python3 init.py= and then =chmod +x build.sh=. - Create directories on the server corresponding to any =*serverpath= variables you have set. From 2886ca7192e4bf9b3e0f7e746c87810071c67861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Fri, 21 Jun 2024 10:25:27 +0100 Subject: [PATCH 08/10] Get latitude and longitude automatically --- .gitignore | 1 - README.org | 7 ++-- generateplaces.py | 89 +++++++++++++++---------------------------- variables-template.py | 2 + 4 files changed, 36 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index 997bc77..0793b3c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,4 @@ gamebuild/* !gamebuild/*.png placebuild/* !placebuild/.gitkeep -places.py variables.py \ No newline at end of file diff --git a/README.org b/README.org index de4e97a..3b49572 100644 --- a/README.org +++ b/README.org @@ -3,8 +3,9 @@ * About The scripts in this repository take information from a structured set of =.org= files and use them to build static webpages that track various activities (so far, gaming and travelling). These pages can be used as a replacement for third-party services e.g. Backloggery. * Dependencies -- =python3= +- =geopy= if you are tracking places visited (install via pip) - =orgparse= (install via pip) +- =python3= - =rclone= (for syncing to the server) * General setup ** Structure of the .org files @@ -40,8 +41,8 @@ In =variables.py=, edit: - =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=. -- If new places have been added since the last build, they will be added to =places.py= and the terminal will signal this. Add the latitude and longitude for these places in =places.py= before building again. +- 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). * First run (or if adding any new trackers) - Run =python3 init.py= and then =chmod +x build.sh=. - Create directories on the server corresponding to any =*serverpath= variables you have set. diff --git a/generateplaces.py b/generateplaces.py index 78a5804..89ce26c 100644 --- a/generateplaces.py +++ b/generateplaces.py @@ -1,6 +1,6 @@ import orgparse,os,re,sys,variables from datetime import datetime -import sys,variables +from geopy.geocoders import Nominatim try: if sys.argv[1] == "local": @@ -10,7 +10,7 @@ try: except: local = False -if variables.trackgames == True: +if variables.trackplaces == True: thisyear = datetime.now().strftime("%Y") @@ -18,6 +18,8 @@ if variables.trackgames == True: concernedfiles = [] + geo = Nominatim(user_agent="python3") + while year < int(thisyear) + 1: month = 0 while month < 13: @@ -59,7 +61,11 @@ if variables.trackgames == True: else: dates = filedate if status == "new": - thedict = {"name":placename,"dates":[dates]} + try: + lookup = placename + ", " + variables.disambig[placename] + except: + lookup = placename + thedict = {"name":placename,"dates":[dates],"lat":geo.geocode(lookup).latitude,"long":geo.geocode(lookup).longitude} places.append(thedict) else: twodict = {"name":placename,"dates":[dates]} @@ -74,59 +80,24 @@ if variables.trackgames == True: theplaces = sorted(places,key=lambda d: d["name"]) - if os.path.isfile("places.py"): - import places - newplaces = [] - for place in theplaces: - for location in places.places: - if place["name"] == location["name"]: - break - else: - newplaces.append(place["name"]) - if len(newplaces) > 0: - with open("places.py","rb+") as editfile: - editfile.seek(-2, os.SEEK_END) - editfile.truncate() - appendfile = open("places.py","a") - for place in newplaces: - appendfile.write(",\n{\"name\":\"" + place + "\",\"lat\":0,\"long\":0}") - appendfile.write("]") - appendfile.close() - print("Add latitudes and longitudes in places.py before running again") - else: - alllats = [] - alllongs = [] - import places - for place in places.places: - 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") - else: - writefile = open("places.py","w") - writefile.write("places = [") - for place in theplaces: - writefile.write("{\"name\":\"" + place["name"] + "\",\"lat\":0,\"long\":0}") - if place != theplaces[-1]: - writefile.write(",\n") - writefile.write("]") - writefile.close() - print("Add latitudes and longitudes in places.py before running again") + 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/variables-template.py b/variables-template.py index 360de53..e051c84 100644 --- a/variables-template.py +++ b/variables-template.py @@ -46,3 +46,5 @@ placeserverpath = "" placestartyear = 0 placecss = "" + +# disambig = {"london":"england","belfast":"northern ireland"} From 94ce340e8f6f98f35bc1d7e1154e4b383fb539a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Fri, 6 Dec 2024 18:36:40 +0000 Subject: [PATCH 09/10] Add script for displaying record collection --- .gitignore | 1 + README.org | 23 +++++++++-- generateplaces.py | 2 +- generaterecords.py | 88 ++++++++++++++++++++++++++++++++++++++++++ init.py | 3 ++ recordbuild/large.png | Bin 0 -> 18924 bytes recordbuild/small.png | Bin 0 -> 27803 bytes variables-template.py | 14 +++++++ 8 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 generaterecords.py create mode 100644 recordbuild/large.png create mode 100644 recordbuild/small.png diff --git a/.gitignore b/.gitignore index 0793b3c..b09ed1f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ gamebuild/* !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 3b49572..a920785 100644 --- a/README.org +++ b/README.org @@ -1,17 +1,21 @@ #+TITLE: Trackers * About -The scripts in this repository take information from a structured set of =.org= files and use them to build static webpages that track various activities (so far, gaming and travelling). These pages can be used as a replacement for third-party services e.g. Backloggery. +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 -- =geopy= if you are tracking places visited (install via pip) - =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 -Rename =variables-template.py= to =variables.py= and edit: +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 @@ -43,6 +47,19 @@ In =variables.py=, edit: ** 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 directories on the server corresponding to any =*serverpath= variables you have set. diff --git a/generateplaces.py b/generateplaces.py index 89ce26c..d35d3e0 100644 --- a/generateplaces.py +++ b/generateplaces.py @@ -93,7 +93,7 @@ if variables.trackplaces == True: writefile.write("\n\n \n \n \n \n Map\n \n \n \n \n \n \n
\n \n \n \n \n
\n