import os import gamesort,skeleton,variables from datetime import datetime,timedelta """ Generates history page and RSS feed """ def history(local=False): # delete existing files if not os.path.isdir("build/history"): os.mkdir("build/history") if os.path.exists("build/history/index.html"): os.remove("build/history/index.html") if os.path.exists("build/feed.xml"): os.remove("build/feed.xml") # write header skeleton.headerwrite("build/history/index.html","history",local) output = "build/history/index.html" filewrite = open(output, "a") filewrite.write("
\n
\n") feedwrite = open("build/feed.xml", "a") feedwrite.write("\n\n \n \n Static backlog\n " + variables.domain + variables.serverpath + "backlog\n Feed for gaming updates\n en-gb") theyear = int(gamesort.thisyear) while theyear > 2016: 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 gamesort.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: filewrite.write("
\n") if checkdate != event["date"]: filewrite.write("

" + event["date"].strftime("%Y-%m-%d") + "

\n") filewrite.write("
\n
" + event["action"] + "\n
\n
\n
" + event["name"] + "\n (" + event["console"] + ")\n
\n
\n
\n") feedwrite.write(" \n " + event["action"] + " " + event["name"] + " (" + event["console"] + ")\n " + event["date"].strftime("%a, %-d %b %Y") + " 00:00:00 UT\n " + variables.domain + variables.serverpath + "history\n " + event["action"] + "-" + event["name"].replace(" ","-") + "-" + event["console"] + "\n " + event["action"] + " " + event["name"] + " (" + event["console"] + ")\n \n") checkdate = event["date"] theyear -= 1 feedwrite.write("
\n
") feedwrite.close() filewrite.write("
\n") theyear = int(gamesort.thisyear) filewrite.write("
\n") while theyear > 2016: yeargames = 0 yearplaying = 0 for game in gamesort.games: if game["initialdate"].year == theyear: try: if game["gameplay"]: if game["id"] not in variables.endlessgames: yeargames += 1 except: yeargames += 1 for game in gamesort.games: try: if game["beaten"].year == theyear: yeargames -= 1 except: try: if game["completed"].year == theyear: yeargames -= 1 except: pass yearbacklog = [] for game in gamesort.games: try: if game["completed"].year == theyear: yearbacklog.append(game) except: try: if game["beaten"].year == theyear: yearbacklog.append(game) except: if game["initialdate"].year == theyear: yearbacklog.append(game) yearcompleted = 0 yearbeaten = 0 yearstarted = 0 yearadded = 0 yeartotal = len(yearbacklog) if yeartotal > 0: for game in yearbacklog: try: if game["initialdate"].year == theyear: yearadded += 1 except: pass try: if game["firstplayed"].year == theyear: yearstarted += 1 except: pass try: if game["completed"].year == theyear: yearcompleted += 1 except: pass try: if game["beaten"].year == theyear: yearbeaten += 1 except: pass compare = [] compare.append(yearadded) compare.append(yearstarted) compare.append(yearbeaten) compare.append(yearcompleted) maxvalue = max(compare) filewrite.write("
\n

" + str(theyear) + " Summary\n Backlog ") if yeargames > 0: filewrite.write("▲ " + str(yeargames)) elif yeargames == 0: filewrite.write(" 0") elif yeargames < 0: filewrite.write("▼ " + str(yeargames * -1)) filewrite.write("

\n
\n
Added
\n
" + str(yearadded) + "
\n
\n
\n
\n
\n
\n
\n
Started
\n
" + str(yearstarted) + "
\n
\n
\n
\n
\n
\n
\n
Beat
\n
" + str(yearbeaten) + "
\n
\n
\n
\n
\n
\n
\n
Completed
\n
" + str(yearcompleted) + "
\n
\n
\n
\n
\n
\n
\n") theyear -= 1 filewrite.write("
\n
\n") filewrite.close() skeleton.footerwrite("build/history/index.html") if __name__ == "__main__": history(True)