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"
try:
if game["completed"]:
cardstring += "
\n"
except:
try:
if game["beaten"]:
cardstring += "
\n"
except:
try:
if game["gameplay"]:
if game["id"] in endlessgames:
cardstring += "
\n"
else:
cardstring += "
\n"
except:
cardstring += "
\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
Notes \n
" + game["recent"] + "
\n
\n"
except:
pass
cardstring += "
\n
\n
Status \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
Currently \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
Platform \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
Last Updated \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 \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