import datetime from importlib import import_module from dateutil.relativedelta import relativedelta """ Remove test file """ fffandoms = ["FF1","FF2","FF3","FF4","FF5","FF6","FF7","FF8","FF9","FFX","FF11","FF12","FF13","FF14","FF15","FF16"] """ Code to generate the fic header div """ def ficgen(ficno,unique=False,output="output.html",local=False): # convert to three-digit number if ficno < 10: ficnostring = "00" + str(ficno) elif ficno < 100: ficnostring = "0" + str(ficno) else: ficnostring = str(ficno) # open the file ficfile = "originalsmeta." + ficnostring fileread = import_module(ficfile) # open translation file if there is one try: if fileread.translation: if fileread.translation < 10: translationstring = "00" + str(fileread.translation) elif fileread.translation < 100: translationstring = "0" + str(fileread.translation) else: translationstring = str(fileread.translation) translationfile = "translationsmeta." + translationstring transread = import_module(translationfile) except: pass try: if fileread.revealdate > datetime.datetime.now(): revealed = False else: revealed = True except: revealed = True if revealed == True: # write to output file filewrite = open(output, "a") filewrite.write("
Summary: " + transread.summary) try: filewrite.write(" " + fileread.summary + "
\n") except: filewrite.write("\n") except: try: filewrite.write("Summary: " + fileread.summary + "
\n") except: pass elif transread.language == "fr": try: filewrite.write("Summary: " + fileread.summary) try: filewrite.write(" " + transread.summary + "
\n") except: filewrite.write("\n") except: try: filewrite.write("Summary: " + transread.summary + "
\n") except: pass except: try: filewrite.write("" + fileread.summary + "
\n") except: pass # set up notes paragraph if required if (fileread.datewords[0])["date"].year < 2011: juvenilia = True else: juvenilia = False try: if fileread.notes: filewrite.write("Notes: ") except: try: if fileread.event: filewrite.write("
Notes: ") except: if juvenilia: filewrite.write("
Notes: ") # if juvenilia, add age if juvenilia: age = relativedelta((fileread.datewords[0])["date"], datetime.datetime(1993,6,28)).years filewrite.write("Age at time of writing: " + str(age) + ".") try: if fileread.notes: filewrite.write(" ") except: pass # write event details if there are any try: if fileread.eventname == "fail-fandomanon": filewrite.write("In response to prompt at fail_fandomanon: " + fileread.prompt + ".") try: if fileread.notes: filewrite.write(" ") except: pass elif fileread.eventname == "robotsoup": filewrite.write("Written for kalloway’s " + fileread.eventdeets + " fest.") try: if fileread.notes: filewrite.write(" ") except: pass else: filewrite.write("Written for ") try: if fileread.eventlocation == "dwcomm": filewrite.write("" + fileread.eventname.replace("-","_") + "") elif fileread.eventlocation == "dwjournal": filewrite.write("" + fileread.eventname.replace("-","_")+ "") elif fileread.eventlocation == "ljjournal": filewrite.write("" + fileread.eventname.replace("-","_")+ "") except: if fileread.eventname == "Semaine de la fic française": filewrite.write("Semaine de la fic française") else: filewrite.write(fileread.eventname) try: if fileread.eventfrequency == "annual": filewrite.write(" " + str((fileread.datewords[0])["date"].year)) else: filewrite.write(" " + fileread.eventfrequency) except: pass if fileread.event == "prompt": filewrite.write(", in response to ") try: if fileread.recip: try: if fileread.recipsite == "dw": filewrite.write("" + fileread.recip.replace("-","_") + "") elif fileread.recipsite == "ao3": try: if fileread.recippseud: filewrite.write("" + fileread.recippseud + " (" + fileread.recip + ")") except: filewrite.write("" + fileread.recip + "") elif fileread.recipsite == "tumblr": filewrite.write("" + fileread.recip + "") except: filewrite.write(fileread.recip) filewrite.write("’s ") except: pass filewrite.write("prompt, " + fileread.prompt + ".") try: if fileread.notes: filewrite.write(" ") except: pass elif fileread.event == "exchange" or fileread.event == "ao3exchange": filewrite.write(", a gift for ") try: if fileread.recipsite == "dw": filewrite.write("" + fileread.recip.replace("-","_") + "") elif fileread.recipsite == "ao3": try: if fileread.recippseud: filewrite.write("" + fileread.recippseud + " (" + fileread.recip + ")") except: filewrite.write("" + fileread.recip + "") elif fileread.recipsite == "tumblr": filewrite.write("" + fileread.recip + "") except: filewrite.write(fileread.recip) filewrite.write(".") try: if fileread.notes: filewrite.write(" ") except: pass else: filewrite.write(".") try: if fileread.notes: filewrite.write(" ") except: pass except: pass # write notes if there are any try: filewrite.write(fileread.notes + "
\n") except: try: if fileread.event: filewrite.write("\n") except: if juvenilia: filewrite.write("\n") filewrite.write("