diff --git a/.gitignore b/.gitignore index 0b84df0..221ed36 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -*.html \ No newline at end of file +__pycache__/ +build/* +!build/*.css +!build/*.png +variables.py \ No newline at end of file diff --git a/README.org b/README.org index 244cc42..4b4153d 100644 --- a/README.org +++ b/README.org @@ -1,12 +1,10 @@ #+TITLE: Trackers -* Roadmap -** Books -- something goodreads or storygraph-esque; goodreads relies heavily on cover art, storygraph on genre and other user-submitted data so neither is brilliant for this tbh -- not started -** Films -- letterboxd, but … a text-only version? -- not started -** Games -- backloggery beta version: see [[https://backloggery.club/demo][here]] -- basic script is created +* Tracking games with a backloggery clone +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 +- =description=: content for the “about” section (can include HTML tags) +- =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) diff --git a/backlog.py b/backlog.py new file mode 100644 index 0000000..329de6f --- /dev/null +++ b/backlog.py @@ -0,0 +1,408 @@ +import os +import cardstring,gamesort,skeleton,variables +from pathlib import Path +from datetime import datetime,timedelta + +""" +Generates backlog page +""" + +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") + # write header + 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 = [] + def nowplaying(): + for console in gamesort.consolelists: + if len(console["games"]) > 0: + thegame = (console["games"])[-1] + try: + if thegame["gameplay"] > (datetime.now() - timedelta(days=180)): + try: + if thegame["completed"]: + if thegame["completed"] >= thegame["gameplay"]: + playing = False + else: + playing = True + except: + try: + if thegame["beaten"]: + if thegame["beaten"] >= thegame["gameplay"]: + playing = False + else: + playing = True + except: + playing = True + else: + playing = False + except: + playing = False + if playing == True: + playingnow.append(thegame) + + nowplaying() + + playingnow = sorted(playingnow,key=lambda d: d["lastupdate"],reverse=True) + + for game in playingnow: + if playingnow.index(game) == 0: + filewrite.write(cardstring.playcard(game,local)) + else: + filewrite.write(cardstring.playcard(game,local,True)) + + filewrite.write("
\n") + + # BACKLOG BREAKDOWN + + filewrite.write("

Backlog Breakdown

\n
\n
\n
\n \n
\n \n " + gamesort.thisyear + " Backlog\n ") + + if yeargames > 0: + filewrite.write("⬆") + elif yeargames < 0: + filewrite.write("⬇") + + filewrite.write(str(abs(yeargames)) + "\n \n \n") + + yearbacklog = [] + for game in gamesort.games: + try: + if game["completed"].year == int(gamesort.thisyear): + yearbacklog.append(game) + except: + try: + if game["beaten"].year == int(gamesort.thisyear): + yearbacklog.append(game) + except: + if game["initialdate"].year == int(gamesort.thisyear): + yearbacklog.append(game) + + yearcompleted = 0 + yearbeaten = 0 + yearendless = 0 + yearunfinished = 0 + yeartotal = len(yearbacklog) + if yeartotal > 0: + for game in yearbacklog: + try: + if game["completed"]: + yearcompleted += 1 + except: + try: + if game["beaten"]: + yearbeaten += 1 + except: + try: + if game["gameplay"]: + if game["id"] in variables.endlessgames: + yearendless += 1 + else: + yearunfinished += 1 + except: + pass + yearunplayed = yeartotal - (yearcompleted + yearbeaten + yearunfinished + yearendless) + yeartakeup = 100 + if yearunplayed > 0: + filewrite.write(" \n \n") + yeartakeup = yeartakeup - round(((yearunplayed/yeartotal)*100),1) + if yearunfinished > 0: + filewrite.write(" \n \n") + yeartakeup = yeartakeup - round(((yearunfinished/yeartotal)*100),1) + if yearbeaten > 0: + filewrite.write(" \n \n") + yeartakeup = yeartakeup - round(((yearbeaten/yeartotal)*100),1) + if yearcompleted > 0: + filewrite.write(" \n \n") + yeartakeup = yeartakeup - round(((yearcompleted/yeartotal)*100),1) + if yearendless > 0: + filewrite.write(" \n \n") + + filewrite.write(" \n
\n
\n
\n
\n
") + if ((backlog/gamesort.total(gamesort.games))*100) > 50: + filewrite.write("\n Active Backlog · " + str(backlog) + " · " + str(round(((backlog/gamesort.total(gamesort.games))*100),1)) + "%") + filewrite.write("\n
\n
") + if ((backlog/gamesort.total(gamesort.games))*100) <= 50: + filewrite.write("\n Active Backlog · " + str(backlog) + " · " + str(round(((backlog/gamesort.total(gamesort.games))*100),1)) + "%") + filewrite.write("\n
\n
\n") + + compare = [] + compare.append(gamesort.unplayed(gamesort.games)) + compare.append(gamesort.unfinished(gamesort.games)) + compare.append(gamesort.beaten(gamesort.games)) + compare.append(gamesort.completed(gamesort.games)) + compare.append(gamesort.endless(gamesort.games)) + maxvalue = max(compare) + + 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") + + # PLATFORM SUMMARY + + filewrite.write("

Platform Summary

\n
\n") + + listofconsoles = sorted(variables.consoles,key=lambda d: d["name"]) + + for console in listofconsoles: + consolegames = [] + for game in gamesort.games: + if game["console"] == console["code"]: + consolegames.append(game) + ccompleted = 0 + cbeaten = 0 + cendless = 0 + cunfinished = 0 + ctotal = len(consolegames) + if ctotal > 0: + filewrite.write("
\n " + console["name"] + "\n " + console["shortname"] + "\n
\n") + for game in consolegames: + try: + if game["completed"]: + ccompleted += 1 + except: + try: + if game["beaten"]: + cbeaten += 1 + except: + try: + if game["gameplay"]: + if game["id"] in variables.endlessgames: + cendless += 1 + else: + cunfinished += 1 + except: + pass + cunplayed = ctotal - (ccompleted + cbeaten + cunfinished + cendless) + 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") + +if __name__ == "__main__": + backlog(True) diff --git a/360.png b/build/360.png similarity index 100% rename from 360.png rename to build/360.png diff --git a/3DS.png b/build/3DS.png similarity index 100% rename from 3DS.png rename to build/3DS.png diff --git a/B.png b/build/B.png similarity index 100% rename from B.png rename to build/B.png diff --git a/C.png b/build/C.png similarity index 100% rename from C.png rename to build/C.png diff --git a/E.png b/build/E.png similarity index 100% rename from E.png rename to build/E.png diff --git a/NDS.png b/build/NDS.png similarity index 100% rename from NDS.png rename to build/NDS.png diff --git a/PC.png b/build/PC.png similarity index 100% rename from PC.png rename to build/PC.png diff --git a/PS2.png b/build/PS2.png similarity index 100% rename from PS2.png rename to build/PS2.png diff --git a/PS3.png b/build/PS3.png similarity index 100% rename from PS3.png rename to build/PS3.png diff --git a/PS5.png b/build/PS5.png similarity index 100% rename from PS5.png rename to build/PS5.png diff --git a/Switch.png b/build/Switch.png similarity index 100% rename from Switch.png rename to build/Switch.png diff --git a/UF.png b/build/UF.png similarity index 100% rename from UF.png rename to build/UF.png diff --git a/UP.png b/build/UP.png similarity index 100% rename from UP.png rename to build/UP.png diff --git a/backloggery.css b/build/backloggery.css similarity index 95% rename from backloggery.css rename to build/backloggery.css index 13a0394..8b76c7d 100644 --- a/backloggery.css +++ b/build/backloggery.css @@ -400,10 +400,6 @@ div.profile main { width:100% } -.platform-card a { - cursor: default; -} - .platform-card .bars { border-radius:0 4px 4px 0; display:-webkit-inline-box; @@ -584,7 +580,6 @@ div.profile main { -ms-flex-align:center; align-items:center; margin:-5px 20px -5px 0; - cursor: default; } .status-tally a div { @@ -757,8 +752,6 @@ div.profile main { margin-right:.5rem} } -/* NEW */ - .game-item .game-info { -webkit-box-align:start; -ms-flex-align:start; @@ -859,3 +852,45 @@ div.profile main { .history .box_1 { width: 95%; } + +div.profile aside { + grid-area:side; + margin-top:1.5rem; + position: sticky; +} + +/* NEW */ + +.library .filters { +margin:.25rem 0 1.5rem; +width:100%} + +.library .filters>div { +padding:1rem; +width:95%} + +/* .library .filters .empty-filters { + border:2px solid rgba(0,0,0,.5); + background-color:var(--active-secondary); + color:var(--active-secondary-text); + border-radius:.5rem; + margin:.5rem auto; + opacity:.8; + padding:.4rem; + text-align:center} + + .library .filters .empty-filters:hover { + opacity:1} */ + +.library .filters .item { +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; +padding:.4rem 1rem .5rem} + +.library .filters .item:hover { +opacity:1} diff --git a/nowplaying.png b/build/nowplaying.png similarity index 100% rename from nowplaying.png rename to build/nowplaying.png diff --git a/paused.png b/build/paused.png similarity index 100% rename from paused.png rename to build/paused.png diff --git a/cardstring.py b/cardstring.py new file mode 100644 index 0000000..d6bd9b7 --- /dev/null +++ b/cardstring.py @@ -0,0 +1,200 @@ +import gamesort,variables +from pathlib import Path +from datetime import datetime,timedelta + +home = str(Path.home()) + +def playcard(game,local=False,decay=False): + cardstring = "" + if decay == True: + cardstring += "
\n" + else: + cardstring += "
\n" + cardstring += " \n
\n
\n" + for console in variables.consoles: + 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: + if game["gameplay"]: + if game["id"] in variables.endlessgames: + cardstring += " \"E\"\n" + else: + cardstring += " \"UF\"\n" + except: + cardstring += " \"UP\"\n" + cardstring += "
\n
\n
" + game["name"] + "
\n" + try: + if len(game["recent"]) > 1: + cardstring += "
" + game["recent"] + "
\n" + except: + pass + try: + if game["gameplay"]: + try: + if game["completed"]: + if game["gameplay"] > game["completed"]: + if game["gameplay"] < (datetime.now() - timedelta(days=180)): + cardstring += "
\n
\n \n
\n" + else: + cardstring += " \n
\n \"⯈\"\n
\n" + else: + cardstring += " \n
\n \n
\n" + except: + try: + if game["beaten"]: + if game["gameplay"] > game["beaten"]: + if game["gameplay"] < (datetime.now() - timedelta(days=180)): + cardstring += " \n
\n \n
\n" + else: + cardstring += " \n
\n \"⯈\"\n
\n" + else: + cardstring += " \n
\n \n
\n" + except: + if game["gameplay"] < (datetime.now() - timedelta(days=180)): + if game["id"] in variables.endlessgames: + cardstring += " \n
\n \n
\n" + else: + cardstring += " \n
\n \"⏸\"\n
\n" + else: + cardstring += " \n
\n \"⯈\"\n
\n" + except: + cardstring += " \n
\n \n
\n" + cardstring += "
\n
\n
\n
\n" + try: + if len(game["recent"]) > 1: + cardstring += "
\n \n
" + game["recent"] + "
\n
\n" + except: + pass + cardstring += "
\n
\n \n

" + try: + if game["completed"]: + cardstring += "Completed" + except: + try: + if game["beaten"]: + cardstring += "Beaten" + except: + try: + if game["gameplay"]: + if game["id"] in variables.endlessgames: + cardstring += "Endless" + else: + cardstring += "Unfinished" + except: + cardstring += "Unplayed" + cardstring += "

\n
\n
\n \n

" + try: + if game["gameplay"]: + try: + if game["completed"]: + if game["gameplay"] > game["completed"]: + if game["gameplay"] < (datetime.now() - timedelta(days=180)): + cardstring += "Not playing" + else: + cardstring += "Playing" + else: + cardstring += "Not playing" + except: + try: + if game["beaten"]: + if game["gameplay"] > game["beaten"]: + if game["gameplay"] < (datetime.now() - timedelta(days=180)): + cardstring += "Not playing" + else: + cardstring += "Playing" + else: + cardstring += "Not playing" + except: + if game["gameplay"] < (datetime.now() - timedelta(days=180)): + if game["id"] in variables.endlessgames: + cardstring += "Not playing" + else: + cardstring += "Paused" + else: + cardstring += "Playing" + except: + cardstring += "Not playing" + cardstring += "

\n
\n
\n
\n
\n
\n \n

" + for console in variables.consoles: + if game["console"] == console["code"]: + cardstring += console["name"] + cardstring += "

\n
\n
\n \n

" + game["lastupdate"].strftime("%Y-%m-%d") + "

\n
\n
\n
\n
\n
\n

Milestones

\n
\n
\n
" + game["initialdate"].strftime("%Y-%m-%d") + "
\n
\n Added
\n
\n" + try: + if game["firstplayed"]: + cardstring += "
\n
" + game["firstplayed"].strftime("%Y-%m-%d") + "
\n
\n Started
\n
\n" + except: + pass + try: + if game["beaten"]: + cardstring += "
\n
" + game["beaten"].strftime("%Y-%m-%d") + "
\n
\n Beaten
\n
\n" + except: + pass + try: + if game["completed"]: + cardstring += "
\n
" + game["completed"].strftime("%Y-%m-%d") + "
\n
\n Completed
\n
\n" + except: + pass + cardstring += "
\n
\n
\n
\n
\n" + return cardstring + +if __name__ == "__main__": + playcard(gamesort.games[0],True) diff --git a/games.py b/games.py deleted file mode 100644 index 3afe79d..0000000 --- a/games.py +++ /dev/null @@ -1,676 +0,0 @@ -import orgparse,os,re -from pathlib import Path -from datetime import datetime,timedelta - -home = str(Path.home()) -thisyear = datetime.now().strftime("%Y") - -basedir = home + "/Documents/drive/org/journal/" - -if os.path.exists("backlog.html"): - os.remove("backlog.html") -writeindex = open("backlog.html", "a") - -if os.path.exists("library.html"): - os.remove("library.html") -writelibrary = open("library.html", "a") - -year = 2016 - -concernedfiles = [] - -endlessgames = ["the sims 4 (pc)","american truck simulator (pc)","civilization iv (pc)","final fantasy xiv (pc)","medieval ii: total war (pc)","tabletop simulator (pc)","train simulator 2020 (pc)","theatrhythm curtain call (nintendo 3ds)"] - -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 = basedir + 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 - -games = [] -gamenames = [] -holding = [] - -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 == "games": - for action in node.children: - for game in action.children: - name = re.sub(" \(.*\)","",game.heading) - if game.heading not in gamenames: - status = "new" - gamenames.append(game.heading) - else: - status = "existing" - console = (re.findall("\(.*\)",game.heading)[0])[1:-1] - if status == "new": - thedict = {"id":game.heading,"name":name,"initialdate":dateobj,"console":console,game.parent.heading:dateobj,"recent":game.body,"lastupdate":dateobj} - if game.parent.heading != "acquired": - thedict.update({"firstplayed":dateobj}) - games.append(thedict) - else: - twodict = {"id":game.heading,game.parent.heading:dateobj,"lastupdate":dateobj} - if len(game.body) > 1: - twodict.update({"recent":game.body}) - for origgame in games: - if twodict["id"] == origgame["id"]: - try: - if origgame["firstplayed"]: - playedbefore = True - except: - playedbefore = False - if playedbefore == False: - twodict.update({"firstplayed":dateobj}) - holding.append(twodict) - for gameupdate in holding: - for origgame in games: - if gameupdate["id"] == origgame["id"]: - gamemerge = {**origgame, **gameupdate} - games.remove(origgame) - games.insert(0,gamemerge) - holding.remove(gameupdate) - except: - pass - -games = sorted(games,key=lambda d: d["lastupdate"]) - -ps5list = [] -for game in games: - if game["console"] == "ps5": - ps5list.append(game) - -ps2list = [] -for game in games: - if game["console"] == "ps2": - ps2list.append(game) - -ps3list = [] -for game in games: - if game["console"] == "ps3": - ps3list.append(game) - -xbox360list = [] -for game in games: - if game["console"] == "xbox 360": - xbox360list.append(game) - -pclist = [] -for game in games: - if game["console"] == "pc": - pclist.append(game) - -dslist = [] -for game in games: - if game["console"] == "nintendo ds": - dslist.append(game) - -switchlist = [] -for game in games: - if game["console"] == "nintendo switch": - switchlist.append(game) - -threedslist = [] -for game in games: - if game["console"] == "nintendo 3ds": - threedslist.append(game) - -writeindex.write("\n\n \n \n \n \n \n \n Selfhostery etc.\n \n \n \n
\n
\n
\n
\n \n") - -# NOW PLAYING - -writeindex.write("
\n
\n

Now Playing

\n
\n") - -playingnow = [] - -def nowplaying(consolelist): - if len(consolelist) > 0: - thegame = consolelist[-1] - try: - if thegame["gameplay"] > (datetime.now() - timedelta(days=180)): - try: - if thegame["completed"]: - if thegame["completed"] > thegame["gameplay"]: - playing = False - else: - playing = True - except: - try: - if thegame["beaten"]: - if thegame["beaten"] > thegame["gameplay"]: - playing = False - else: - playing = True - except: - playing = True - if playing: - playingnow.append(thegame) - except: - pass - -nowplaying(dslist) -nowplaying(threedslist) -nowplaying(switchlist) -nowplaying(pclist) -nowplaying(ps2list) -nowplaying(ps3list) -nowplaying(ps5list) -nowplaying(xbox360list) - -playingnow = sorted(playingnow,key=lambda d: d["lastupdate"],reverse=True) - -decay = False - -def playcard(game,page): - cardstring = "" - if decay == True: - cardstring += "
\n" - else: - cardstring += "
\n" - cardstring += " \n
\n
\n" - if game["console"] == "ps5": - cardstring += " \"PS5\"\n" - elif game["console"] == "ps2": - cardstring += " \"PS2\"\n" - elif game["console"] == "ps3": - cardstring += " \"PS3\"\n" - elif game["console"] == "nintendo switch": - cardstring += " \"Switch\"\n" - elif game["console"] == "nintendo ds": - cardstring += " \"DS\"\n" - elif game["console"] == "nintendo 3ds": - cardstring += " \"3DS\"\n" - elif game["console"] == "xbox 360": - cardstring += " \"Xbox360\"\n" - elif game["console"] == "pc": - cardstring += " \"PC\"\n" - cardstring += "
\n
\n
\n" - try: - if game["completed"]: - cardstring += " \"C\"\n" - except: - try: - if game["beaten"]: - cardstring += " \"B\"\n" - except: - try: - if game["gameplay"]: - if game["id"] in endlessgames: - cardstring += " \"E\"\n" - else: - cardstring += " \"UF\"\n" - except: - cardstring += " \"UP\"\n" - cardstring += "
\n
\n
" + game["name"] + "
\n" - try: - if len(game["recent"]) > 1: - cardstring += "
" + game["recent"] + "
\n" - except: - pass - try: - if game["gameplay"]: - try: - if game["completed"]: - if game["gameplay"] > game["completed"]: - if game["gameplay"] < (datetime.now() - timedelta(days=180)): - cardstring += "
\n
\n \n
\n" - else: - cardstring += "
\n
\n \"⯈\"\n
\n" - else: - cardstring += "
\n
\n \n
\n" - except: - try: - if game["beaten"]: - if game["gameplay"] > game["beaten"]: - if game["gameplay"] < (datetime.now() - timedelta(days=180)): - cardstring += "
\n
\n \n
\n" - else: - cardstring += "
\n
\n \"⯈\"\n
\n" - else: - cardstring += " \n
\n \n
\n" - except: - if game["gameplay"] < (datetime.now() - timedelta(days=180)): - if game["id"] in endlessgames: - cardstring += " \n
\n \n
\n" - else: - cardstring += " \n
\n \"⏸\"\n
\n" - else: - cardstring += " \n
\n \"⯈\"\n
\n" - except: - cardstring += " \n
\n \n
\n" - cardstring += " \n
\n
\n
\n" - try: - if len(game["recent"]) > 1: - cardstring += "
\n \n
" + game["recent"] + "
\n
\n" - except: - pass - cardstring += "
\n
\n \n

" - try: - if game["completed"]: - cardstring += "Completed" - except: - try: - if game["beaten"]: - cardstring += "Beaten" - except: - try: - if game["gameplay"]: - if game["id"] in endlessgames: - cardstring += "Endless" - else: - cardstring += "Unfinished" - except: - cardstring += "Unplayed" - cardstring += "

\n
\n
\n \n

" - try: - if game["gameplay"]: - try: - if game["completed"]: - if game["gameplay"] > game["completed"]: - if game["gameplay"] < (datetime.now() - timedelta(days=180)): - cardstring += "Not playing" - else: - cardstring += "Playing" - else: - cardstring += "Not playing" - except: - try: - if game["beaten"]: - if game["gameplay"] > game["beaten"]: - if game["gameplay"] < (datetime.now() - timedelta(days=180)): - cardstring += "Not playing" - else: - cardstring += "Playing" - else: - cardstring += "Not playing" - except: - if game["gameplay"] < (datetime.now() - timedelta(days=180)): - if game["id"] in endlessgames: - cardstring += "Not playing" - else: - cardstring += "Paused" - else: - cardstring += "Playing" - except: - cardstring += "Not playing" - cardstring += "

\n
\n
\n
\n
\n
\n \n

" - if game["console"] == "ps5": - cardstring += "PlayStation 5" - elif game["console"] == "ps2": - cardstring += "PlayStation 2" - elif game["console"] == "ps3": - cardstring += "PlayStation 3" - elif game["console"] == "nintendo switch": - cardstring += "Nintendo Switch" - elif game["console"] == "nintendo ds": - cardstring += "Nintendo DS" - elif game["console"] == "nintendo 3ds": - cardstring += "Nintendo 3DS" - elif game["console"] == "xbox 360": - cardstring += "XBox 360" - elif game["console"] == "pc": - cardstring += "PC" - cardstring += "

\n
\n
\n \n

" + game["lastupdate"].strftime("%Y-%m-%d") + "

\n
\n
\n
\n
\n
\n

Milestones

\n
\n
\n
" + game["initialdate"].strftime("%Y-%m-%d") + "
\n
\n Added
\n
\n" - try: - if game["firstplayed"]: - cardstring += "
\n
" + game["firstplayed"].strftime("%Y-%m-%d") + "
\n
\n Started
\n
\n" - except: - pass - try: - if game["beaten"]: - cardstring += "
\n
" + game["beaten"].strftime("%Y-%m-%d") + "
\n
\n Beaten
\n
\n" - except: - pass - try: - if game["completed"]: - cardstring += "
\n
" + game["completed"].strftime("%Y-%m-%d") + "
\n
\n Completed
\n
\n" - except: - pass - cardstring += "
\n
\n
\n
\n
\n" - if page == "main": - writeindex.write(cardstring) - elif page == "library": - writelibrary.write(cardstring) - -for game in playingnow: - playcard(game,"main") - decay = True - -writeindex.write(" \n") - -# BACKLOG BREAKDOWN - -writeindex.write("

Backlog Breakdown

\n
\n
\n
\n
\n \n Total Games\n " + str(len(games)) + "\n \n \n") - -completed = 0 -beaten = 0 -endless = 0 -unfinished = 0 -total = len(games) -if total > 0: - for game in games: - try: - if game["completed"]: - completed += 1 - except: - try: - if game["beaten"]: - beaten += 1 - except: - try: - if game["gameplay"]: - if game["id"] in endlessgames: - endless += 1 - else: - unfinished += 1 - except: - pass -unplayed = total - (completed + beaten + unfinished + endless) -backlog = unfinished + unplayed -takeup = 100 -if unplayed > 0: - writeindex.write(" \n \n") - takeup = takeup - round(((unplayed/total)*100),1) -if unfinished > 0: - writeindex.write(" \n \n") - takeup = takeup - round(((unfinished/total)*100),1) -if beaten > 0: - writeindex.write(" \n \n") - takeup = takeup - round(((beaten/total)*100),1) -if completed > 0: - writeindex.write(" \n \n") - takeup = takeup - round(((completed/total)*100),1) -if endless > 0: - writeindex.write(" \n \n") - -yeargames = 0 -yearplaying = 0 -for game in games: - if game["initialdate"].year == int(thisyear): - try: - if game["gameplay"]: - if game["id"] not in endlessgames: - yeargames += 1 - except: - yeargames += 1 -for game in games: - try: - if game["beaten"].year == int(thisyear): - yeargames -= 1 - except: - try: - if game["completed"].year == int(thisyear): - yeargames -= 1 - except: - pass - -writeindex.write(" \n
\n
\n \n " + thisyear + " Backlog\n ") - -if yeargames > 0: - writeindex.write("⬆") -elif yeargames < 0: - writeindex.write("⬇") - -writeindex.write(str(abs(yeargames)) + "\n \n \n") - -yearbacklog = [] -for game in games: - try: - if game["completed"].year == int(thisyear): - yearbacklog.append(game) - except: - try: - if game["beaten"].year == int(thisyear): - yearbacklog.append(game) - except: - if game["initialdate"].year == int(thisyear): - yearbacklog.append(game) - -yearcompleted = 0 -yearbeaten = 0 -yearendless = 0 -yearunfinished = 0 -yeartotal = len(yearbacklog) -if yeartotal > 0: - for game in yearbacklog: - try: - if game["completed"]: - yearcompleted += 1 - except: - try: - if game["beaten"]: - yearbeaten += 1 - except: - try: - if game["gameplay"]: - if game["id"] in endlessgames: - yearendless += 1 - else: - yearunfinished += 1 - except: - pass -yearunplayed = yeartotal - (yearcompleted + yearbeaten + yearunfinished + yearendless) -yeartakeup = 100 -if yearunplayed > 0: - writeindex.write(" \n \n") - yeartakeup = yeartakeup - round(((yearunplayed/yeartotal)*100),1) -if yearunfinished > 0: - writeindex.write(" \n \n") - yeartakeup = yeartakeup - round(((yearunfinished/yeartotal)*100),1) -if yearbeaten > 0: - writeindex.write(" \n \n") - yeartakeup = yeartakeup - round(((yearbeaten/yeartotal)*100),1) -if yearcompleted > 0: - writeindex.write(" \n \n") - yeartakeup = yeartakeup - round(((yearcompleted/yeartotal)*100),1) -if yearendless > 0: - writeindex.write(" \n \n") - -writeindex.write(" \n
\n
\n
\n
\n
") -if ((backlog/total)*100) > 50: - writeindex.write("\n Active Backlog · " + str(backlog) + " · " + str(round(((backlog/total)*100),1)) + "%") -writeindex.write("\n
\n
") -if ((backlog/total)*100) <= 50: - writeindex.write("\n Active Backlog · " + str(backlog) + " · " + str(round(((backlog/total)*100),1)) + "%") -writeindex.write("\n
\n
\n") - -compare = [] -compare.append(unplayed) -compare.append(unfinished) -compare.append(beaten) -compare.append(completed) -compare.append(endless) -maxvalue = max(compare) - -if unplayed / maxvalue > 0.5: - writeindex.write(" \n
" + str(unplayed) + "
\n
\n \n
\n
\n
" + str(round(((unplayed/total)*100),1)) + "% Unplayed
\n
\n
\n") -else: - writeindex.write(" \n
" + str(unplayed) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((unplayed/total)*100),1)) + "% Unplayed
\n
\n
\n") - -if unfinished / maxvalue > 0.5: - writeindex.write(" \n
" + str(unfinished) + "
\n
\n \n
\n
\n
" + str(round(((unfinished/total)*100),1)) + "% Unfinished
\n
\n
\n") -else: - writeindex.write(" \n
" + str(unfinished) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((unfinished/total)*100),1)) + "% Unfinished
\n
\n
\n") - -if beaten / maxvalue > 0.5: - writeindex.write(" \n
" + str(beaten) + "
\n
\n \n
\n
\n
" + str(round(((beaten/total)*100),1)) + "% Beaten
\n
\n
\n") -else: - writeindex.write(" \n
" + str(beaten) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((beaten/total)*100),1)) + "% Beaten
\n
\n
\n") - -if completed / maxvalue > 0.5: - writeindex.write(" \n
" + str(completed) + "
\n
\n \n
\n
\n
" + str(round(((completed/total)*100),1)) + "% Completed
\n
\n
\n") -else: - writeindex.write(" \n
" + str(completed) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((completed/total)*100),1)) + "% Completed
\n
\n
\n") - -if endless / maxvalue > 0.5: - writeindex.write(" \n
" + str(endless) + "
\n
\n \n
\n
\n
" + str(round(((endless/total)*100),1)) + "% Endless
\n
\n
\n") -else: - writeindex.write(" \n
" + str(endless) + "
\n
\n \n
\n
\n
\n
\n
" + str(round(((endless/total)*100),1)) + "% Endless
\n
\n
\n") - -writeindex.write("
\n
\n
") - -# PLATFORM SUMMARY - -writeindex.write("

Platform Summary

\n
\n") - -def liststats(title,abbr,consolelist): - completed = 0 - beaten = 0 - endless = 0 - unfinished = 0 - total = len(consolelist) - if total > 0: - writeindex.write("
\n " + title + "\n " + abbr + "\n
\n") - for game in consolelist: - try: - if game["completed"]: - completed += 1 - except: - try: - if game["beaten"]: - beaten += 1 - except: - try: - if game["gameplay"]: - if game["id"] in endlessgames: - endless += 1 - else: - unfinished += 1 - except: - pass - unplayed = total - (completed + beaten + unfinished + endless) - if unplayed > 0: - writeindex.write(" " + str(unplayed) + "\n") - if unfinished > 0: - writeindex.write(" " + str(unfinished) + "\n") - if beaten > 0: - writeindex.write(" " + str(beaten) + "\n") - if completed > 0: - writeindex.write(" " + str(completed) + "\n") - if endless > 0: - writeindex.write(" " + str(endless) + "\n") - writeindex.write("
\n " + str(total) + "\n Total\n \n
\n") - -liststats("Nintendo DS","DS",dslist) -liststats("Nintendo 3DS","3DS",threedslist) -liststats("Nintendo Switch","Switch",switchlist) -liststats("PC","PC",pclist) -liststats("PlayStation 2","PS2",ps2list) -liststats("PlayStation 3","PS3",ps3list) -liststats("PlayStation 5","PS5",ps5list) -liststats("Xbox 360","Xbox360",xbox360list) - -writeindex.write("
\n \n
\n \n \n \n \n \n\n") - -# LIBRARY - -writelibrary.write("\n\n \n \n \n \n \n \n Selfhostery etc.\n \n \n \n
\n
\n
\n
\n \n
\n
\n
\n
\n Total Found " + str(total) + "\n
\n") -if unplayed > 0: - writelibrary.write("
" + str(unplayed) + "
\n") -if unfinished > 0: - writelibrary.write("
" + str(unfinished) + "
\n") -if beaten > 0: - writelibrary.write("
" + str(beaten) + "
\n") -if completed > 0: - writelibrary.write("
" + str(completed) + "
\n") -if endless > 0: - writelibrary.write("
" + str(endless) + "
\n") -writelibrary.write("
\n
\n") - -newgames = sorted(games,key=lambda d: d["id"]) - -decay = False - -for game in newgames: - playcard(game,"library") - -# HISTORY - -theyear = int(thisyear) -while theyear > 2016: - added = 0 - started = 0 - beat = 0 - completed = 0 - beatorcompleted = 0 - for game in games: - if game["initialdate"].year == theyear: - added += 1 - try: - if game["firstplayed"].year == theyear: - started += 1 - except: - pass - try: - if game["beaten"].year == theyear: - beat += 1 - beatorcompleted += 1 - try: - if game["completed"].year == theyear: - completed += 1 - except: - pass - except: - try: - if game["completed"].year == theyear: - completed += 1 - beatorcompleted += 1 - except: - pass - backlog = added - beatorcompleted - print(str(theyear) + " Summary") - if backlog > 0: - print("Backlog ▲ " + str(backlog)) - elif backlog == 0: - print("Backlog 0") - elif backlog < 0: - print("Backlog ▼ " + str(backlog * -1)) - print("Added " + str(added)) - print("Started " + str(started)) - print("Beat " + str(beat)) - print("Completed " + str(completed)) - yearlist = [] - enddate = datetime.strptime((str(theyear) + "-12-31"),"%Y-%m-%d") - startdate = datetime.strptime((str(theyear) + "-01-01"),"%Y-%m-%d") - eachdate = enddate - while eachdate >= startdate: - for game in games: - if game["initialdate"] == eachdate: - yearlist.append({"date":eachdate,"name":game["name"],"console":game["console"],"action":"Added"}) - try: - if game["firstplayed"] == eachdate: - yearlist.append({"date":eachdate,"name":game["name"],"console":game["console"],"action":"Started"}) - except: - pass - try: - if game["beaten"] == eachdate: - yearlist.append({"date":eachdate,"name":game["name"],"console":game["console"],"action":"Beat"}) - except: - pass - try: - if game["completed"] == eachdate: - yearlist.append({"date":eachdate,"name":game["name"],"console":game["console"],"action":"Completed"}) - except: - pass - eachdate -= timedelta(days=1) - checkdate = enddate - for event in yearlist: - if checkdate != event["date"]: - print(event["date"].strftime("%Y-%-m-%-d")) - print(event["action"] + ": " + event["name"] + " (" + event["console"] + ")") - checkdate = event["date"] - theyear -= 1 diff --git a/gamesort.py b/gamesort.py new file mode 100644 index 0000000..16bdb8c --- /dev/null +++ b/gamesort.py @@ -0,0 +1,187 @@ +import orgparse,os,re,variables +from pathlib import Path +from datetime import datetime + +""" +Load in the list of games from a set of .org files. +""" + +home = str(Path.home()) +thisyear = datetime.now().strftime("%Y") + +year = 2016 + +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 + +games = [] +gamenames = [] +holding = [] + +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 == "games": + for action in node.children: + for game in action.children: + name = re.sub(" \(.*\)","",game.heading) + if game.heading not in gamenames: + status = "new" + gamenames.append(game.heading) + else: + status = "existing" + console = (re.findall("\(.*\)",game.heading)[0])[1:-1] + if status == "new": + thedict = {"id":game.heading,"name":name,"initialdate":dateobj,"console":console,game.parent.heading:dateobj,"recent":game.body,"lastupdate":dateobj} + if game.parent.heading != "acquired": + thedict.update({"firstplayed":dateobj}) + games.append(thedict) + else: + twodict = {"id":game.heading,game.parent.heading:dateobj,"lastupdate":dateobj} + if len(game.body) > 1: + twodict.update({"recent":game.body}) + for origgame in games: + if twodict["id"] == origgame["id"]: + try: + if origgame["firstplayed"]: + playedbefore = True + except: + playedbefore = False + if playedbefore == False: + twodict.update({"firstplayed":dateobj}) + holding.append(twodict) + for gameupdate in holding: + for origgame in games: + if gameupdate["id"] == origgame["id"]: + gamemerge = {**origgame, **gameupdate} + games.remove(origgame) + games.insert(0,gamemerge) + holding.remove(gameupdate) + except: + pass + +games = sorted(games,key=lambda d: d["lastupdate"]) + +consolelists = [] +for console in variables.consoles: + consolegames = [] + for game in games: + if game["console"] == console["code"]: + consolegames.append(game) + consolelists.append({"code":console["code"],"name":console["name"],"games":consolegames}) + +def completed(selection): + completed = 0 + for game in selection: + try: + if game["completed"]: + completed += 1 + except: + pass + return completed + +def beaten(selection): + beaten = 0 + for game in selection: + try: + if game["completed"]: + pass + except: + try: + if game["beaten"]: + beaten += 1 + except: + pass + return beaten + +def endless(selection): + endless = 0 + for game in selection: + try: + if game["completed"]: + pass + except: + try: + if game["beaten"]: + pass + except: + try: + if game["gameplay"]: + if game["id"] in variables.endlessgames: + endless += 1 + except: + pass + return(endless) + +def unfinished(selection): + unfinished = 0 + for game in selection: + try: + if game["completed"]: + pass + except: + try: + if game["beaten"]: + pass + except: + try: + if game["gameplay"]: + if game["id"] not in variables.endlessgames: + unfinished += 1 + except: + pass + return(unfinished) + +def total(selection): + return len(selection) + +def unplayed(selection): + unplayed = total(selection) - (completed(selection) + beaten(selection) + unfinished(selection) + endless(selection)) + return(unplayed) + +# completed = 0 +# beaten = 0 +# endless = 0 +# unfinished = 0 +# total = len(games) +# if total > 0: +# for game in games: +# try: +# if game["completed"]: +# completed += 1 +# except: +# try: +# if game["beaten"]: +# beaten += 1 +# except: +# try: +# if game["gameplay"]: +# if game["id"] in variables.endlessgames: +# endless += 1 +# else: +# unfinished += 1 +# except: +# pass +# unplayed = total - (completed + beaten + unfinished + endless) + +if __name__ == "__main__": + print(endless(games)) diff --git a/generate.py b/generate.py new file mode 100644 index 0000000..77ea908 --- /dev/null +++ b/generate.py @@ -0,0 +1,23 @@ +import sys + +import backlog +import library +import sublibrary + +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) + else: + backlog.backlog() + library.library() + sublibrary.sublibrary() diff --git a/history.py b/history.py new file mode 100644 index 0000000..fde968e --- /dev/null +++ b/history.py @@ -0,0 +1,97 @@ +import os +import gamesort,skeleton +from datetime import datetime,timedelta + +""" +Generates history page +""" + +def history(local=False): + # delete existing file + if os.path.exists("build/history/index.html"): + os.remove("build/history/index.html") + # write header + skeleton.headerwrite("build/history/index.html","history",local) + output = "build/history/index.html" + filewrite = open(output, "a") + + theyear = int(gamesort.thisyear) + while theyear > 2016: + added = 0 + started = 0 + beat = 0 + completed = 0 + beatorcompleted = 0 + for game in gamesort.games: + if game["initialdate"].year == theyear: + added += 1 + try: + if game["firstplayed"].year == theyear: + started += 1 + except: + pass + try: + if game["beaten"].year == theyear: + beat += 1 + beatorcompleted += 1 + try: + if game["completed"].year == theyear: + completed += 1 + except: + pass + except: + try: + if game["completed"].year == theyear: + completed += 1 + beatorcompleted += 1 + except: + pass + backlog = added - beatorcompleted + print(str(theyear) + " Summary") + if backlog > 0: + print("Backlog ▲ " + str(backlog)) + elif backlog == 0: + print("Backlog 0") + elif backlog < 0: + print("Backlog ▼ " + str(backlog * -1)) + print("Added " + str(added)) + print("Started " + str(started)) + print("Beat " + str(beat)) + print("Completed " + str(completed)) + yearlist = [] + enddate = datetime.strptime((str(theyear) + "-12-31"),"%Y-%m-%d") + startdate = datetime.strptime((str(theyear) + "-01-01"),"%Y-%m-%d") + eachdate = enddate + while eachdate >= startdate: + for game in gamesort.games: + if game["initialdate"] == eachdate: + yearlist.append({"date":eachdate,"name":game["name"],"console":game["console"],"action":"Added"}) + try: + if game["firstplayed"] == eachdate: + yearlist.append({"date":eachdate,"name":game["name"],"console":game["console"],"action":"Started"}) + except: + pass + try: + if game["beaten"] == eachdate: + yearlist.append({"date":eachdate,"name":game["name"],"console":game["console"],"action":"Beat"}) + except: + pass + try: + if game["completed"] == eachdate: + yearlist.append({"date":eachdate,"name":game["name"],"console":game["console"],"action":"Completed"}) + except: + pass + eachdate -= timedelta(days=1) + checkdate = enddate + for event in yearlist: + if checkdate != event["date"]: + print(event["date"].strftime("%Y-%m-%d")) + print(event["action"] + ": " + event["name"] + " (" + event["console"] + ")") + checkdate = event["date"] + theyear -= 1 + + filewrite.close() + skeleton.footerwrite("build/history/index.html") + +if __name__ == "__main__": + history(True) diff --git a/library.py b/library.py new file mode 100644 index 0000000..31f86a7 --- /dev/null +++ b/library.py @@ -0,0 +1,40 @@ +import os +import cardstring,gamesort,skeleton + +""" +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") + # write header + 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("
" + str(gamesort.unplayed(gamesort.games)) + "
\n") + if gamesort.unfinished(gamesort.games) > 0: + filewrite.write("
" + str(gamesort.unfinished(gamesort.games)) + "
\n") + if gamesort.beaten(gamesort.games) > 0: + filewrite.write("
" + str(gamesort.beaten(gamesort.games)) + "
\n") + if gamesort.completed(gamesort.games) > 0: + filewrite.write("
" + str(gamesort.completed(gamesort.games)) + "
\n") + if gamesort.endless(gamesort.games) > 0: + filewrite.write("
" + str(gamesort.endless(gamesort.games)) + "
\n") + filewrite.write("
\n
\n") + + newgames = sorted(gamesort.games,key=lambda d: d["id"]) + + for game in newgames: + filewrite.write(cardstring.playcard(game,local)) + + filewrite.close() + skeleton.footerwrite("build/library/index.html") + +if __name__ == "__main__": + library(True) diff --git a/skeleton.py b/skeleton.py new file mode 100644 index 0000000..12a98bc --- /dev/null +++ b/skeleton.py @@ -0,0 +1,55 @@ +import variables +from pathlib import Path + +""" +Generate the skeleton for an HTML page. +""" + +home = str(Path.home()) + +def headerwrite(output,section,local=False): + header = open(output, "a") + header.write("\n\n \n \n \n \n \n \n Selfhostery\n \n \n \n
\n
\n \n
\n
\n
\n") + header.write(" Backlog\n Library\n History\n
\n") + header.close() + +def footerwrite(output): + footer = open(output, "a") + footer.write("
\n
\n
\n
\n \n\n") + footer.close() + +if __name__ == "__main__": + headerwrite("build/backlog/index.html","backlog",True) + footerwrite("test.html") diff --git a/sublibrary.py b/sublibrary.py new file mode 100644 index 0000000..ad5564f --- /dev/null +++ b/sublibrary.py @@ -0,0 +1,151 @@ +import os +import cardstring,gamesort,skeleton,variables +from pathlib import Path + +""" +Generates sublibrary pages +""" + +home = str(Path.home()) + +def sublibrary(local=False): + statuses = ["all","completed","beaten","unfinished","endless","unplayed"] + consoleextra = [{"shortname":"all"}] + consolesplus = variables.consoles + consoleextra + for console in consolesplus: + gameslist = [] + for game in gamesort.games: + if console["shortname"] == "all": + gameslist.append(game) + elif game["console"] == console["code"]: + gameslist.append(game) + for status in statuses: + filterlist = [] + if status == "all": + for game in gameslist: + filterlist.append(game) + elif status == "completed": + for game in gameslist: + try: + if game["completed"]: + filterlist.append(game) + except: + pass + elif status == "beaten": + for game in gameslist: + try: + if game["completed"]: + pass + except: + try: + if game["beaten"]: + filterlist.append(game) + except: + pass + elif status == "unfinished": + for game in gameslist: + try: + if game["completed"]: + pass + except: + try: + if game["beaten"]: + pass + except: + try: + if game["gameplay"]: + if game["id"] not in variables.endlessgames: + filterlist.append(game) + except: + pass + elif status == "endless": + for game in gameslist: + try: + if game["completed"]: + pass + except: + try: + if game["beaten"]: + pass + except: + try: + if game["gameplay"]: + if game["id"] in variables.endlessgames: + filterlist.append(game) + except: + pass + elif status == "unplayed": + for game in gameslist: + try: + if game["completed"]: + pass + except: + try: + if game["beaten"]: + pass + except: + try: + if game["gameplay"]: + pass + except: + filterlist.append(game) + if not os.path.isdir("build/library/" + console["shortname"].lower() + "-" + status): + if len(filterlist) > 0: + os.mkdir("build/library/" + console["shortname"].lower() + "-" + status) + if os.path.exists("build/library/" + console["shortname"].lower() + "-" + status + "/index.html"): + os.remove("build/library/" + console["shortname"].lower() + "-" + status + "/index.html") + # write header + if len(filterlist) > 0: + skeleton.headerwrite(("build/library/" + console["shortname"].lower() + "-" + status + "/index.html"),"sublibrary",local) + output = "build/library/" + console["shortname"].lower() + "-" + status + "/index.html" + filewrite = open(output, "a") + filewrite.write("
\n
\n
\n
Filtered by\n") + if console["shortname"] != "all": + filewrite.write(" 1 Platform\n") + if status != "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("
" + str(gamesort.unplayed(filterlist)) + "
\n") + if gamesort.unfinished(filterlist) > 0: + filewrite.write("
" + str(gamesort.unfinished(filterlist)) + "
\n") + if gamesort.beaten(filterlist) > 0: + filewrite.write("
" + str(gamesort.beaten(filterlist)) + "
\n") + if gamesort.completed(filterlist) > 0: + filewrite.write("
" + str(gamesort.completed(filterlist)) + "
\n") + if gamesort.endless(filterlist) > 0: + filewrite.write("
" + str(gamesort.endless(filterlist)) + "
\n") + filewrite.write("
\n
\n") + + newgames = sorted(filterlist,key=lambda d: d["id"]) + + for game in newgames: + filewrite.write(cardstring.playcard(game,local)) + + filewrite.close() + skeleton.footerwrite("build/library/" + console["shortname"].lower() + "-" + status + "/index.html") + +if __name__ == "__main__": + sublibrary(True) diff --git a/variables-template.py b/variables-template.py new file mode 100644 index 0000000..b34e522 --- /dev/null +++ b/variables-template.py @@ -0,0 +1,22 @@ +""" +User-defined variables live here. +""" + +endlessgames = [] + +orgpath = "" + +localpath = "" + +serverpath = "" + +description = "" + +consoles = [{"code":"ps5","name":"PlayStation 5","shortname":"PS5","img":"PS5"}, + {"code":"ps2","name":"PlayStation 2","shortname":"PS2","img":"PS2"}, + {"code":"ps3","name":"PlayStation 3","shortname":"PS3","img":"PS3"}, + {"code":"xbox 360","name":"Xbox 360","shortname":"Xbox360","img":"360"}, + {"code":"nintendo ds","name":"Nintendo DS","shortname":"DS","img":"NDS"}, + {"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"}]