import datetime, os, shutil from importlib import import_module """ Warning: code in this file is /particularly/ bizarre and non-optimised. """ """ Write the wee blurb for each fic """ def ficsum(ficcount,year,month=0,showfandom=True,local=False): 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) elif os.path.exists("translationsmeta/" + ficcountstring + ".py"): ficfile = "translationsmeta." + ficcountstring fileread = import_module(ficfile) else: fileread = False if fileread: try: theorig = "originalsmeta." + str(fileread.original) origfile = import_module(theorig) except: pass try: fandom = "/".join(origfile.fandom) except: fandom = "/".join(fileread.fandom) thechars = "" try: if "OW" not in origfile.fandom: if "gen" not in origfile.genre: try: thechars = origfile.ship[0] except: chars = [] try: chars.extend(origfile.charpov) except: pass try: chars.extend(origfile.charmain) except: pass if chars != []: thechars = ", ".join(chars) else: thechars = "" else: chars = [] try: chars.extend(origfile.charpov) except: pass try: chars.extend(origfile.charmain) except: pass if chars != []: thechars = ", ".join(chars) else: thechars = "" else: thechars = "" except: if "OW" not in fileread.fandom: if "gen" not in fileread.genre: try: thechars = fileread.ship[0] except: chars = [] try: chars.extend(fileread.charpov) except: pass try: chars.extend(fileread.charmain) except: pass if chars != []: thechars = ", ".join(chars) else: thechars = "" else: chars = [] try: chars.extend(fileread.charpov) except: pass try: chars.extend(fileread.charmain) except: pass if chars != []: thechars = ", ".join(chars) else: thechars = "" else: thechars = "" if thechars == "": thechars = "no characters specified" if fileread.language == "fr": language = "French" else: language = "" try: rating = origfile.rating except: rating = fileread.rating genre = [] try: for thegenre in origfile.genre: if thegenre == "gen": genre.append(thegenre) elif thegenre == "het" or thegenre == "pre-het": genre.append("het") elif thegenre == "slash" or thegenre == "pre-slash" or thegenre == "poly slash": genre.append("slash") elif thegenre == "femslash": genre.append("femslash") elif thegenre == "poly": genre.append("multi") elif thegenre == "masturbation": genre.append("other") except: for thegenre in fileread.genre: if thegenre == "gen": genre.append(thegenre) elif thegenre == "het" or thegenre == "pre-het": genre.append("het") elif thegenre == "slash" or thegenre == "pre-slash" or thegenre == "poly slash": genre.append("slash") elif thegenre == "femslash": genre.append("femslash") elif thegenre == "poly": genre.append("multi") elif thegenre == "masturbation": genre.append("other") try: if origfile.warnings: warnings = "?!" except: try: if fileread.warnings: warnings = "?!" except: warnings = "" words = 0 for datewords in fileread.datewords: if month: if int((datewords["date"]).year) == year: if int((datewords["date"]).month) == month: words += datewords["words"] else: if int((datewords["date"]).year) == year: words += datewords["words"] ficstring = "" ficstring += "" if showfandom: ficstring += fandom if thechars or language: ficstring += ", " if thechars: ficstring += thechars if language: ficstring += ", " if language: ficstring += language ficstring += "" if rating == "g": ficstring += "  G " elif rating == "t": ficstring += "  T " elif rating == "m": ficstring += "  M " elif rating == "e": ficstring += "  E " for thegenre in genre: if thegenre == "gen": ficstring += "  ☉ " elif thegenre == "slash": ficstring += "  ♂ " elif thegenre == "het": ficstring += "  ⚤ " elif thegenre == "femslash": ficstring += "  ♀ " elif thegenre == "poly": ficstring += "     " elif thegenre == "other": ficstring += "  ☿ " if warnings: ficstring += "  !? " ficstring += " " + str(words) + "" return ficstring """ Generate stats page for each year """ def yeargen(local=False): yearlist = [] 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) elif os.path.exists("translationsmeta/" + ficcountstring + ".py"): ficfile = "translationsmeta." + ficcountstring fileread = import_module(ficfile) else: fileread = False if fileread: try: if fileread.revealdate > datetime.datetime.now(): revealed = False else: revealed = True except: revealed = True if revealed == True: for date in fileread.datewords: yearlist.append(date["date"].year) yearlist = sorted(list(dict.fromkeys(yearlist))) for year in yearlist: yearpath = "build/stats/" + str(year) if not os.path.isdir(yearpath): os.mkdir(yearpath) if os.path.exists(yearpath + "/index.html"): os.remove(yearpath + "/index.html") filewrite = open(yearpath + "/index.html", "a") filewrite.write("\n\n\n\n\nFic stats " + str(year) + "\n\n\n\n\n\n
\n

Fic stats for " + str(year) + "

\n") allfics = [] ficdeets = [] datesplit = [] 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) elif os.path.exists("translationsmeta/" + ficcountstring + ".py"): ficfile = "translationsmeta." + ficcountstring fileread = import_module(ficfile) else: fileread = False if fileread: try: if fileread.revealdate > datetime.datetime.now(): revealed = False else: revealed = True except: revealed = True if revealed == True: for date in fileread.datewords: if (date["date"]).year == year: allfics.append(ficcountstring) allfics = sorted(list(dict.fromkeys(allfics))) for fic in allfics: if os.path.exists("originalsmeta/" + fic + ".py"): ficfile = "originalsmeta." + fic fileread = import_module(ficfile) elif os.path.exists("translationsmeta/" + fic + ".py"): ficfile = "translationsmeta." + fic fileread = import_module(ficfile) else: fileread = False if fileread: try: if fileread.revealdate > datetime.datetime.now(): revealed = False else: revealed = True except: revealed = True if revealed == True: try: fandom = fileread.fandom event = fileread.event eventname = fileread.eventname try: eventlocation = fileread.eventlocation except: eventlocation = False except: try: if fileread.original: theorig = "originalsmeta." + str(fileread.original) origfile = import_module(theorig) try: fandom = origfile.fandom event = origfile.event eventname = origfile.eventname try: eventlocation = fileread.eventlocation except: eventlocation = False except: event = False eventname = False eventlocation = False except: event = False eventname = False eventlocation = False ficwords = 0 for dateword in fileread.datewords: if (dateword["date"]).year == year: ficwords = (dateword["words"]) ficdict = {"number":fic,"words":ficwords,"fandom":fandom,"event":event,"eventname":eventname,"eventlocation":eventlocation,"date":dateword["date"]} ficdeets.append(ficdict) datesplit.append(ficdict) combinedeets = [] for fic in ficdeets: if combinedeets == []: ficlogged = True combinedeets.append(fic) else: ficlogged = False for newfic in combinedeets: if ficlogged == False: if fic["number"] == newfic["number"]: ficlogged = True newfic["words"] += fic["words"] if ficlogged == False: combinedeets.append(fic) ficdeets = combinedeets totalwords = 0 for fic in ficdeets: totalwords += fic["words"] if len(allfics) == 1: filewrite.write("

Total: " + str(len (allfics)) + " fic, " + str(totalwords) + " words

\n") else: filewrite.write("

Total: " + str(len (allfics)) + " fics, " + str(totalwords) + " words

") prompts = [] for fic in ficdeets: if fic["event"] == "prompt": prompts.append(fic) if prompts: promptwords = 0 for fic in prompts: promptwords += fic["words"] promptdict = {"type":"Prompt fills","fics":len(prompts),"words":promptwords,"list":prompts} else: promptdict = False unprompted = [] for fic in ficdeets: if fic["event"] == False: unprompted.append(fic) if unprompted: unpromptedwords = 0 for fic in unprompted: unpromptedwords += fic["words"] unprompteddict = {"type":"Unprompted","fics":len(unprompted),"words":unpromptedwords,"list":unprompted} else: unprompteddict = False challenges = [] for fic in ficdeets: if fic["event"] == "challenge": challenges.append(fic) if challenges: challengewords = 0 for fic in challenges: challengewords += fic["words"] challengedict = {"type":"Challenges","fics":len(challenges),"words":challengewords,"list":challenges} else: challengedict = False exchanges = [] for fic in ficdeets: if fic["event"] == "exchange" or fic["event"] == "ao3exchange": exchanges.append(fic) if exchanges: exchangewords = 0 for fic in exchanges: exchangewords += fic["words"] exchangedict = {"type":"Exchanges","fics":len(exchanges),"words":exchangewords,"list":exchanges} else: exchangedict = False byevent = [] if promptdict: byevent.append(promptdict) if unprompteddict: byevent.append(unprompteddict) if challengedict: byevent.append(challengedict) if exchangedict: byevent.append(exchangedict) byevent = sorted(byevent,key=lambda d: d["words"],reverse=True) filewrite.write("

By type

\n\n\n\n\n\n\n\n\n\n") for event in byevent: filewrite.write("\n\n\n\n") filewrite.write("\n
Words per fic type
TypeWords
" + event["type"] + "" + str(event["words"]) + "" + str(event["fics"]) + " fic") if event["fics"] > 1: filewrite.write("s") filewrite.write(", " + str(event["words"]) + " words
\n
Breakdown\n") for eventtype in byevent: filewrite.write("

" + eventtype["type"] + "

\n") eventslist = [] for fic in eventtype["list"]: if fic["eventname"]: eventdeets = {"eventname":fic["eventname"],"eventlocation":fic["eventlocation"],"ficno":fic["number"],"words":fic["words"]} else: eventdeets = {"ficno":fic["number"],"words":fic["words"]} eventslist.append(eventdeets) neweventslist = [] if eventtype["type"] == "Unprompted": neweventslist = eventslist else: for fic in eventslist: if neweventslist == []: ficlogged = True neweventslist.append(fic) else: ficlogged = False for newfic in neweventslist: if ficlogged == False: if fic["eventname"] == newfic["eventname"]: ficlogged = True newfic["words"] = newfic["words"] + fic["words"] if type(newfic["ficno"]) == str: newfic["ficno"] = newfic["ficno"].split() if type(fic["ficno"]) == str: newfic["ficno"].append(fic["ficno"]) if ficlogged == False: neweventslist.append(fic) if eventtype["type"] != "Unprompted": for fic in neweventslist: if type(fic["ficno"]) == str: fic["ficno"] = fic["ficno"].split() neweventslist = sorted(neweventslist,key=lambda d: d["words"],reverse=True) else: neweventslist = sorted(neweventslist,key=lambda d: d["ficno"]) if eventtype["type"] == "Unprompted": filewrite.write("
List\n
    \n") for fic in neweventslist: filewrite.write("
  1. " + str(ficsum(int(fic["ficno"]),year,local=local)) + "
  2. ") filewrite.write("
\n
\n") else: filewrite.write("\n\n\n\n\n\n\n\n\n") for event in neweventslist: filewrite.write("\n\n\n\n") filewrite.write("\n
Words per event
EventWords
") if event["eventlocation"] == "dwcomm": filewrite.write("\"[community" + (event["eventname"]).replace("-","_") + "") elif event["eventlocation"] == "dwjournal": filewrite.write("\"[personal" + (event["eventname"]).replace("-","_")+ "") elif event["eventlocation"] == "ljjournal": filewrite.write("\"[personal" + (event["eventname"]).replace("-","_")+ "") else: filewrite.write(event["eventname"]) filewrite.write("" + str(event["words"]) + "" + str(len(event["ficno"])) + " fic") if len(event["ficno"]) > 1: filewrite.write("s") filewrite.write(", " + str(event["words"]) + " words
\n
List\n") for event in neweventslist: filewrite.write("

") if event["eventlocation"] == "dwcomm": filewrite.write("\"[community" + (event["eventname"]).replace("-","_") + "") elif event["eventlocation"] == "dwjournal": filewrite.write("\"[personal" + (event["eventname"]).replace("-","_")+ "") elif event["eventlocation"] == "ljjournal": filewrite.write("\"[personal" + (event["eventname"]).replace("-","_")+ "") else: filewrite.write(event["eventname"]) filewrite.write("

\n
    \n") for fic in event["ficno"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,local=local)) + "
  2. \n") filewrite.write("
\n") filewrite.write("
\n") fandomlist = [] for fic in ficdeets: fandomlist.extend(fic["fandom"]) fandomlist = sorted(list(dict.fromkeys(fandomlist))) filewrite.write("
\n

By fandom

\n\n\n\n\n\n\n\n\n\n") fandomdeets = [] for fandom in fandomlist: fandomdict = {"name":fandom,"ficno":[],"words":0} for fic in ficdeets: if fandom in fic["fandom"]: fandomdict["ficno"].append(fic["number"]) fandomdict["words"] += fic["words"] fandomdeets.append(fandomdict) fandomdeets = sorted(fandomdeets,key=lambda d: d["words"],reverse=True) for fandom in fandomdeets: filewrite.write("\n\n\n") filewrite.write("\n
Words per fandom
Fandom Words
" + fandom["name"] + "" + str(fandom["words"]) + "" + str(len(fandom["ficno"])) + " fic") if len(fandom["ficno"]) > 1: filewrite.write("s") filewrite.write(", " + str(fandom["words"]) + " words
\n
List") for fandom in fandomdeets: filewrite.write("

" + fandom["name"] + "

\n
    \n") for fic in fandom["ficno"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,showfandom=False,local=local)) + "
  2. \n") filewrite.write("
\n") filewrite.write("
\n

By month

\n\n\n\n\n\n\n\n\n") monthcombine = [] for fic in datesplit: # read the file back in to get the right word count, because dicts are dynamic somehow?? thedate = fic["date"] thefic = fic["number"] if os.path.exists("originalsmeta/" + thefic + ".py"): ficfile = "originalsmeta." + thefic fileread = import_module(ficfile) elif os.path.exists("translationsmeta/" + thefic + ".py"): ficfile = "translationsmeta." + thefic fileread = import_module(ficfile) else: fileread = False if fileread: try: if fileread.revealdate > datetime.datetime.now(): revealed = False else: revealed = True except: revealed = True if revealed == True: for datewords in fileread.datewords: if datewords["date"] == thedate: thewords = datewords["words"] fic["words"] = thewords ficlogged = False if monthcombine == []: if ficlogged == False: ficlogged = True monthcombine.append(fic) else: ficlogged = False for newfic in monthcombine: if ficlogged == False: if fic["number"] == newfic["number"]: if (fic["date"]).month == (newfic["date"]).month: ficlogged = True newfic["words"] += fic["words"] if ficlogged == False: monthcombine.append(fic) jan = {"fics":[],"words":0} feb = {"fics":[],"words":0} mar = {"fics":[],"words":0} apr = {"fics":[],"words":0} may = {"fics":[],"words":0} jun = {"fics":[],"words":0} jul = {"fics":[],"words":0} aug = {"fics":[],"words":0} sep = {"fics":[],"words":0} octo = {"fics":[],"words":0} nov = {"fics":[],"words":0} dec = {"fics":[],"words":0} for fic in monthcombine: if (fic["date"]).month == 1: jan["fics"].append(fic["number"]) jan["words"] += fic["words"] elif (fic["date"]).month == 2: feb["fics"].append(fic["number"]) feb["words"] += fic["words"] elif (fic["date"]).month == 3: mar["fics"].append(fic["number"]) mar["words"] += fic["words"] elif (fic["date"]).month == 4: apr["fics"].append(fic["number"]) apr["words"] += fic["words"] elif (fic["date"]).month == 5: may["fics"].append(fic["number"]) may["words"] += fic["words"] elif (fic["date"]).month == 6: jun["fics"].append(fic["number"]) jun["words"] += fic["words"] elif (fic["date"]).month == 7: jul["fics"].append(fic["number"]) jul["words"] += fic["words"] elif (fic["date"]).month == 8: aug["fics"].append(fic["number"]) aug["words"] += fic["words"] elif (fic["date"]).month == 9: sep["fics"].append(fic["number"]) sep["words"] += fic["words"] elif (fic["date"]).month == 10: octo["fics"].append(fic["number"]) octo["words"] += fic["words"] elif (fic["date"]).month == 11: nov["fics"].append(fic["number"]) nov["words"] += fic["words"] elif (fic["date"]).month == 12: dec["fics"].append(fic["number"]) dec["words"] += fic["words"] wordlist = [] wordlist.append(jan["words"]) wordlist.append(feb["words"]) wordlist.append(mar["words"]) wordlist.append(apr["words"]) wordlist.append(may["words"]) wordlist.append(jun["words"]) wordlist.append(jul["words"]) wordlist.append(aug["words"]) wordlist.append(sep["words"]) wordlist.append(octo["words"]) wordlist.append(nov["words"]) wordlist.append(dec["words"]) mostwords = max(wordlist) filewrite.write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Words per month
MonthWords
Jan" + str(jan["words"]) + "" + str(len(jan["fics"])) + " fic") if len(jan["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(jan["words"]) + " words
Feb" + str(feb["words"]) + "" + str(len(feb["fics"])) + " fic") if len(feb["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(feb["words"]) + " words
Mar" + str(mar["words"]) + "" + str(len(mar["fics"])) + " fic") if len(mar["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(mar["words"]) + " words
Apr" + str(apr["words"]) + "" + str(len(apr["fics"])) + " fic") if len(apr["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(apr["words"]) + " words
May" + str(may["words"]) + "" + str(len(may["fics"])) + " fic") if len(may["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(may["words"]) + " words
Jun" + str(jun["words"]) + "" + str(len(jun["fics"])) + " fic") if len(jun["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(jun["words"]) + " words
Jul" + str(jul["words"]) + "" + str(len(jul["fics"])) + " fic") if len(jul["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(jul["words"]) + " words
Aug" + str(aug["words"]) + "" + str(len(aug["fics"])) + " fic") if len(aug["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(aug["words"]) + " words
Sep" + str(sep["words"]) + "" + str(len(sep["fics"])) + " fic") if len(sep["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(sep["words"]) + " words
Oct" + str(octo["words"]) + "" + str(len(octo["fics"])) + " fic") if len(octo["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(octo["words"]) + " words
Nov" + str(nov["words"]) + "" + str(len(nov["fics"])) + " fic") if len(nov["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(nov["words"]) + " words
Dec" + str(dec["words"]) + "" + str(len(dec["fics"])) + " fic") if len(dec["fics"]) != 1: filewrite.write("s") filewrite.write(", " + str(dec["words"]) + " words
\n
List\n") if len(jan["fics"]) > 0: filewrite.write("

January

\n
    \n") for fic in jan["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,1,local=local)) + "
  2. \n") filewrite.write("
\n") if len(feb["fics"]) > 0: filewrite.write("

February

\n
    \n") for fic in feb["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,2,local=local)) + "
  2. \n") filewrite.write("
\n") if len(mar["fics"]) > 0: filewrite.write("

March

\n
    \n") for fic in mar["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,3,local=local)) + "
  2. \n") filewrite.write("
\n") if len(apr["fics"]) > 0: filewrite.write("

April

\n
    \n") for fic in apr["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,4,local=local)) + "
  2. \n") filewrite.write("
\n") if len(may["fics"]) > 0: filewrite.write("

May

\n
    \n") for fic in may["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,5,local=local)) + "
  2. \n") filewrite.write("
\n") if len(jun["fics"]) > 0: filewrite.write("

June

\n
    \n") for fic in jun["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,6,local=local)) + "
  2. \n") filewrite.write("
\n") if len(jul["fics"]) > 0: filewrite.write("

July

\n
    \n") for fic in jul["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,7,local=local)) + "
  2. \n") filewrite.write("
\n") if len(aug["fics"]) > 0: filewrite.write("

August

\n
    \n") for fic in aug["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,8,local=local)) + "
  2. \n") filewrite.write("
\n") if len(sep["fics"]) > 0: filewrite.write("

September

\n
    \n") for fic in sep["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,9,local=local)) + "
  2. \n") filewrite.write("
\n") if len(octo["fics"]) > 0: filewrite.write("

October

\n
    \n") for fic in octo["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,10,local=local)) + "
  2. \n") filewrite.write("
\n") if len(nov["fics"]) > 0: filewrite.write("

November

\n
    \n") for fic in nov["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,11,local=local)) + "
  2. \n") filewrite.write("
\n") if len(dec["fics"]) > 0: filewrite.write("

December

\n
    \n") for fic in dec["fics"]: filewrite.write("
  1. " + str(ficsum(int(fic),year,12,local=local)) + "
  2. \n") filewrite.write("
\n") filewrite.write("
\n

") listposition = yearlist.index(year) if year != 1998: prevyear = yearlist[listposition - 1] filewrite.write("« " + str(prevyear) + "") thisyear = int(datetime.datetime.now().strftime("%Y")) if year < thisyear: nextyear = yearlist[listposition + 1] filewrite.write("" + str(nextyear) + " »") filewrite.write("

\n
\n\n") filewrite.close() if __name__ == "__main__": yeargen(True)