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"] """ 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("
\n

" + ficnostring) # write ficno including translation if there is one try: filewrite.write("/" + translationstring) except: pass filewrite.write("") # write title if requested if fileread.showtitle: filewrite.write(" " + fileread.title) try: if transread.showtitle: filewrite.write("/" + transread.title) except: pass filewrite.write("") else: try: if transread.showtitle: filewrite.write(" " + transread.title) except: pass if fileread.status == "abandoned": filewrite.write(" ") filewrite.write("

\n\n") # write summary if there is one try: if transread.language == "en": try: filewrite.write("

" + transread.summary) try: filewrite.write(" " + fileread.summary + "

\n") except: filewrite.write("

\n") except: try: filewrite.write("

" + fileread.summary + "

\n") except: pass elif transread.language == "fr": try: filewrite.write("

" + fileread.summary) try: filewrite.write(" " + transread.summary + "

\n") except: filewrite.write("

\n") except: try: filewrite.write("

" + 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("

") except: try: if fileread.event: filewrite.write("

") except: if juvenilia: filewrite.write("

") # 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 \"[communityfail_fandomanon: " + fileread.prompt + ".") try: if fileread.notes: filewrite.write(" ") except: pass elif fileread.eventname == "robotsoup": filewrite.write("Written for \"[personalkalloway’s " + fileread.eventdeets + " fest.") try: if fileread.notes: filewrite.write(" ") except: pass else: filewrite.write("Written for ") try: if fileread.eventlocation == "dwcomm": filewrite.write("\"[community" + fileread.eventname.replace("-","_") + "") elif fileread.eventlocation == "dwjournal": filewrite.write("\"[personal" + fileread.eventname.replace("-","_")+ "") elif fileread.eventlocation == "ljjournal": filewrite.write("\"[personal" + 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("\"[personal" + fileread.recip.replace("-","_") + "") elif fileread.recipsite == "ao3": try: if fileread.recippseud: filewrite.write("\"[archiveofourown.org" + fileread.recippseud + " (" + fileread.recip + ")") except: filewrite.write("\"[archiveofourown.org" + fileread.recip + "") elif fileread.recipsite == "tumblr": filewrite.write("\"[tumblr.com" + 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("\"[personal" + fileread.recip.replace("-","_") + "") elif fileread.recipsite == "ao3": try: if fileread.recippseud: filewrite.write("\"[archiveofourown.org" + fileread.recippseud + " (" + fileread.recip + ")") except: filewrite.write("\"[archiveofourown.org" + fileread.recip + "") elif fileread.recipsite == "tumblr": filewrite.write("\"[tumblr.com" + 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("\n") # write links for translation if required try: if fileread.translation: if transread.language == "en": filewrite.write("\n") except: pass filewrite.write("
\n") filewrite.close()