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))