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