import datetime from importlib import import_module from dateutil.relativedelta import relativedelta 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 linkgen(ficno,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 = "files.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 = "files.translationsmeta." + translationstring transread = import_module(translationfile) except: pass filewrite = open(output, "a") filewrite.write("\n") # write links for translation if required try: if fileread.translation: if transread.language == "en": filewrite.write("\n") except: pass def ficgen(ficno,unique=False,output="output.html",local=False,single=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 = "files.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 = "files.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

no. " + ficnostring + "") try: if translationstring: 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(" (abandoned)") filewrite.write("

\n
\n\n") # write summary if there is one try: if transread.language == "en": try: 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 \"[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.") elif fileread.eventname == "#ficwip": filewrite.write("Written for the #ficwip event " + fileread.eventdeets + "") if fileread.event == "prompt": filewrite.write(", in response to prompt, " + fileread.prompt + "") filewrite.write(".") 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.close() linkgen(ficno,output,local) filewrite = open(output, "a") filewrite.write("
\n") if single: filewrite.write("\n") filewrite.write("
\n") filewrite.close()