import datetime, os from importlib import import_module fffandoms = ["FF1","FF2","FF3","FF4","FF5","FF6","FF7","FF8","FF9","FFX","FF11","FF12","FF13","FF14","FF15","FF16"] import makeheader import headerfooter def charlist(local=False): # delete existing file if os.path.exists("build/ff/characters/index.html"): os.remove("build/ff/characters/index.html") # write header headerfooter.headerwrite("build/ff/characters/index.html","FF fics by character","FF fics by character","

Click on each bar to see fics about that character, organised according to the character’s prominence and then from newest to oldest.

\n

Key to categories:

\n",False,local) # iterate through fandoms characters = [] numbers = ["one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen"] for fandom in fffandoms: thecharacters = [] ficcount = 500 while ficcount > 0: ficcount -= 1 if ficcount < 10: ficcountstring = "00" + str(ficcount) elif ficcount < 100: ficcountstring = "0" + str(ficcount) else: ficcountstring = str(ficcount) if os.path.exists("originalsmeta/" + ficcountstring + ".py"): ficfile = "originalsmeta." + ficcountstring fileread = import_module(ficfile) try: if fileread.revealdate > datetime.datetime.now(): revealed = False else: revealed = True except: revealed = True if revealed == True: if len(fileread.fandom) == 1: if fandom in fileread.fandom: try: thecharacters.extend(fileread.charpov) except: pass try: thecharacters.extend(fileread.charmain) except: pass try: thecharacters.extend(fileread.charsecondary) except: pass try: thecharacters.extend(fileread.charmention) except: pass thecharacters = sorted(list(dict.fromkeys(thecharacters))) for character in thecharacters: if character != "OCs": chardict = {"name":character,"game":(fffandoms.index(fandom) + 1)} characters.append(chardict) charlist = sorted(characters, key=lambda d: d["name"]) for person in charlist: povcount = [] maincount = [] secondarycount = [] mentioncount = [] character = person["name"] searchfandom = fffandoms[(person["game"]) - 1] cssgame = numbers[(person["game"]) - 1] # check all fics in specified fandom ficcount = 500 while ficcount > 0: ficcount -= 1 if ficcount < 10: ficcountstring = "00" + str(ficcount) elif ficcount < 100: ficcountstring = "0" + str(ficcount) else: ficcountstring = str(ficcount) if os.path.exists("originalsmeta/" + ficcountstring + ".py"): countfile = "originalsmeta." + ficcountstring fileread = import_module(countfile) try: if fileread.revealdate > datetime.datetime.now(): revealed = False else: revealed = True except: revealed = True if revealed == True: ficdict = {"thefic":ficcount,"thedate":(fileread.datewords[-1])["date"]} if searchfandom in fileread.fandom: # append to lists try: if character in fileread.charpov: povcount.append(ficdict) except: pass try: if character in fileread.charmain: maincount.append(ficdict) except: pass try: if character in fileread.charsecondary: secondarycount.append(ficdict) except: pass try: if character in fileread.charmention: mentioncount.append(ficdict) except: pass # write details element output = "build/ff/characters/index.html" filewrite = open(output, "a") filewrite.write("
" + character + " ") # write statistics if len(povcount) > 0: filewrite.write("POV: " + str(len(povcount)) + "") if len(maincount) > 0: filewrite.write("main: " + str(len(maincount)) + "") if len(secondarycount) > 0: filewrite.write("secondary: " + str(len(secondarycount)) + "") if len(mentioncount) > 0: filewrite.write("mentioned: " + str(len(mentioncount)) + "") filewrite.write("\n") filewrite.close() # write fic headers in each category if len(povcount) > 0: filewrite = open(output, "a") filewrite.write("

POV character

\n") filewrite.close() povcount = sorted(povcount,key=lambda d: d["thedate"],reverse=True) newpov = [] for fic in povcount: newpov.append(fic["thefic"]) for fic in newpov: makeheader.ficgen(fic,False,output,local) if len(maincount) > 0: filewrite = open(output, "a") filewrite.write("

Main character

\n") filewrite.close() maincount = sorted(maincount,key=lambda d: d["thedate"],reverse=True) newmain = [] for fic in maincount: newmain.append(fic["thefic"]) for fic in newmain: makeheader.ficgen(fic,False,output,local) if len(secondarycount) > 0: filewrite = open(output, "a") filewrite.write("

Secondary character

\n") filewrite.close() secondarycount = sorted(secondarycount,key=lambda d: d["thedate"],reverse=True) newsecondary = [] for fic in secondarycount: newsecondary.append(fic["thefic"]) for fic in newsecondary: makeheader.ficgen(fic,False,output,local) if len(mentioncount) > 0: filewrite = open(output, "a") filewrite.write("

Mentioned

\n") filewrite.close() mentioncount = sorted(mentioncount,key=lambda d: d["thedate"],reverse=True) newmention = [] for fic in mentioncount: newmention.append(fic["thefic"]) for fic in newmention: makeheader.ficgen(fic,False,output,local) filewrite = open(output, "a") filewrite.write("
\n") filewrite.close() # write footer headerfooter.footerwrite("build/ff/characters/index.html",False,local) if __name__ == "__main__": charlist()