import datetime,os import log,skel,tcgcore,variables def crayonlog(colour,event): crayonno = event["crayons"][colour] if variables.british: if colour == "gray": crayonrend = "grey" else: crayonrend = colour else: crayonrend = colour if crayonno > 0: crayonstring = "+" + str(crayonno) + " " + crayonrend else: crayonstring = str(crayonno) + " " + crayonrend return crayonstring def loggen(month=False): if month: if not os.path.isdir("build/log/month"): os.mkdir("build/log/month") if os.path.exists("build/log/month/index.html"): os.remove("build/log/month/index.html") thefile = "build/log/month/index.html" else: if not os.path.isdir("build/log"): os.mkdir("build/log") if os.path.exists("build/log/index.html"): os.remove("build/log/index.html") thefile = "build/log/index.html" skel.headerwrite(thefile,"log") content = open(thefile,"a") content.write("

log

\n

") if month: content.write("Show all") else: content.write("Show current month only") content.write("

\n") if month: thelog = [] for event in log.log: if event["date"].month == datetime.datetime.now().month and event["date"].year == datetime.datetime.now().year: thelog.append(event) thelog = thelog[::-1] else: thelog = log.log[::-1] for event in thelog: if event == "portfolio": logit = False else: try: if event["received"]: logit = True except: try: if event["lost"]: logit = True except: try: if event["crayons"]: logit = True except: logit = False if logit == True: content.write("

" + event["date"].strftime("%Y-%m-%d") + " [" + event["event"] + "]: ") try: if event["received"]: content.write("Received ") receivedlist = sorted(event["received"]) position = 1 for card in receivedlist: content.write(tcgcore.cardtext(card)) if len(receivedlist) != position: content.write(", ") position += 1 content.write(".") try: if event["lost"]: content.write(" ") except: try: if event["crayons"]: content.write(" ") except: pass except: pass try: if event["lost"]: content.write("Lost ") lostlist = sorted(event["lost"]) position = 1 for card in lostlist: content.write(tcgcore.cardtext(card)) if len(lostlist) != position: content.write(", ") position += 1 content.write(".") try: if event["crayons"]: content.write(" ") except: pass except: pass try: if event["crayons"]: content.write("Crayons: ") try: content.write(crayonlog("red",event)) if list(event["crayons"])[-1] != "red": content.write(", ") except: pass try: content.write(crayonlog("orange",event)) if list(event["crayons"])[-1] != "orange": content.write(", ") except: pass try: content.write(crayonlog("yellow",event)) if list(event["crayons"])[-1] != "yellow": content.write(", ") except: pass try: content.write(crayonlog("green",event)) if list(event["crayons"])[-1] != "green": content.write(", ") except: pass try: content.write(crayonlog("blue",event)) if list(event["crayons"])[-1] != "blue": content.write(", ") except: pass try: content.write(crayonlog("purple",event)) if list(event["crayons"])[-1] != "purple": content.write(", ") except: pass try: content.write(crayonlog("brown",event)) if list(event["crayons"])[-1] != "brown": content.write(", ") except: pass try: content.write(crayonlog("gray",event)) except: pass content.write(".") except: pass content.write("

\n") content.close() skel.footerwrite(thefile) def logall(): loggen(False) loggen(True) if __name__ == "__main__": logall()