import os, orgparse, re from pathlib import Path from datetime import datetime home = str(Path.home()) thisyear = datetime.now().strftime("%Y") basedir = home + "/Documents/drive/org/journal/" 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 = 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": games.append({"id":game.heading,"name":name,"initialdate":dateobj,"console":console,game.parent.heading:dateobj,"recent":game.body,"lastupdate":dateobj}) else: thedict = {"id":game.heading,game.parent.heading:dateobj,"lastupdate":dateobj} if len(game.body) > 1: thedict.update({"recent":game.body}) holding.append(thedict) except: pass for gameupdate in holding: for origgame in games: if gameupdate["id"] == origgame["id"]: gamemerge = {**origgame, **gameupdate} games.remove(origgame) games.insert(0,gamemerge) 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) # NOW PLAYING 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 state = "completed" except: try: if thegame["beaten"]: if thegame["beaten"] > thegame["gameplay"]: playing = False else: playing = True state = "beaten" except: playing = True state = "playing" if playing: playingnow.append({"console":thegame["console"],"name":thegame["name"],"date":thegame["gameplay"],"state":state,"note":thegame["recent"]}) 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["date"],reverse=True) for game in playingnow: if len(game["note"]) > 1: print(game["console"] + " → " + game["name"] + " (" + game["state"] + "): " + game["note"]) else: print(game["console"] + " → " + game["name"] + " (" + game["state"] + ")") # BACKLOG BREAKDOWN print("Total Games: " + str(len(games))) yeargames = 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 print(thisyear + " Backlog: " + str(yeargames)) completed = 0 beaten = 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"]: unfinished += 1 except: pass unplayed = total - (completed + beaten + unfinished) backlog = unfinished + unplayed print("Active Backlog • " + str(backlog) + " • " + str(round(((backlog/total)*100),1)) + "%") if unplayed > 0: print(str(unplayed) + " – " + str(round(((unplayed/total)*100),1)) + "% Unplayed") if unfinished > 0: print(str(unfinished) + " – " + str(round(((unfinished/total)*100),1)) + "% Unfinished") if beaten > 0: print(str(beaten) + " – " + str(round(((beaten/total)*100),1)) + "% Beaten") if completed > 0: print(str(completed) + " – " + str(round(((completed/total)*100),1)) + "% Completed") # PLATFORM SUMMARY def liststats(console,consolelist): completed = 0 beaten = 0 unfinished = 0 total = len(consolelist) if total > 0: for game in consolelist: try: if game["completed"]: completed += 1 except: try: if game["beaten"]: beaten += 1 except: try: if game["gameplay"]: unfinished += 1 except: pass unplayed = total - (completed + beaten + unfinished) print(console) if completed > 0: print("Completed: " + str(completed)) if beaten > 0: print("Beaten: " + str(beaten)) if unfinished > 0: print("Unfinished: " + str(unfinished)) if unplayed > 0: print("Unplayed: " + str(unplayed)) print("Total: " + str(total)) liststats("DS",dslist) liststats("3DS",threedslist) liststats("Switch",switchlist) liststats("PC",pclist) liststats("PS2",ps2list) liststats("PS3",ps3list) liststats("PS5",ps5list) liststats("XBOX 360",xbox360list) # LIBRARY def theresults(): newgames = sorted(games,key=lambda d: d["id"]) for game in newgames: try: if (game["completed"]): print(game["console"] + " → " + game["name"] + " (completed)") if len(game["recent"]) > 1: print(game["recent"]) except: try: if (game["beaten"]): print(game["console"] + " → " + game["name"] + " (beaten)") if len(game["recent"]) > 1: print(game["recent"]) except: try: if (game["gameplay"]): print(game["console"] + " → " + game["name"] + " (unfinished)") if len(game["recent"]) > 1: print(game["recent"]) except: print(game["console"] + " → " + game["name"] + " (unplayed)") print("") theresults() # HISTORY # iterate backwards from this year to 2016 # if nothing in this year, "history has yet to be written" # else, for each year: initialdate, gameplay???, beaten, completed???