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)"] 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"]: 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" 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 int(game["initialdate"].year) == int(thisyear): try: if game["completed"]: pass except: try: if game["beaten"]: pass except: yeargames += 1 try: if game["gameplay"]: yearplaying += 1 except: pass writeindex.write(" \n
\n
\n \n " + thisyear + " Backlog\n " + str(yeargames) + "\n \n \n \n \n") if yearplaying > 0: writeindex.write(" \n \n") writeindex.write(" \n
\n
\n
\n
\n
\n Active Backlog · " + str(backlog) + " · " + str(round(((backlog/total)*100),1)) + "%\n
\n
\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) 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