import datetime, os, shutil from importlib import import_module import headerfooter fffandoms = ["FF1","FF2","FF3","FF4","FF5","FF6","FF7","FF8","FF9","FFX","FF11","FF12","FF13","FF14","FF15","FF16"] """ Code to generate comment page """ def commentpage(ficno,directory,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 = directory + "." + ficnostring fileread = import_module(ficfile) # determine if comments page try: if any(item in fffandoms for item in fileread.fandom): fffandom = True else: fffandom = False except: origfile = "files.originalsmeta." + str(fileread.original) origread = import_module(origfile) if any(item in fffandoms for item in origread.fandom): fffandom = True else: fffandom = False if fffandom: commentspage = True else: timeelapsed = datetime.datetime.now() - (fileread.datewords[-1])["date"] if timeelapsed.days < 730: commentspage = True else: try: if fileread.event == "ao3exchange" and (fileread.datewords[0])["date"].year > 2019: commentspage = True else: try: if fileread.comments: commentspage = True except: commentspage = False except: try: if fileread.comments: commentspage = True except: commentspage = False if commentspage: commentspath = "build/comments/" + ficnostring if not os.path.isdir(commentspath): os.mkdir(commentspath) if os.path.exists(commentspath + "/index.html"): os.remove(commentspath + "/index.html") # write to output file headerfooter.headerwrite(commentspath + "/index.html","Comments for fic no. " + ficnostring,"Comments for fic no. " + ficnostring + "","",False,local) filewrite = open(commentspath + "/index.html", "a") if fffandom or timeelapsed.days < 730: filewrite.write("
Comments will be posted manually; please expect a delay between submitting your comment and seeing it below!
\n\n") else: try: if fileread.event == "ao3exchange" and (fileread.datewords[0])["date"].year > 2019: filewrite.write("Comments aren’t open for this fic. They’re still available on AO3, however, as this was written for an AO3-based gift exchange.
\n") except: pass try: if fileread.comments: filewrite.write("If you left one of these comments and would like it to be removed from the archive, please email me.
\nMy replies are included only if they were originally posted on this site.
\n") for comment in fileread.comments: filewrite.write("" + comment["reply"] + "
\nComments I receive are archived on this site and linked back to the original. If you don’t want your comments from other sources archived here, or if you require any changes to the presentation of your comments, please email me. Please note, however, that this website is not indexed by search engines.
\nIf you don’t have JavaScript switched off, you can leave comments on the relevant comment pages for each fic (where this is enabled). Please leave your email address if you’d like notification of any reply. If you’d like a link from your pseudonym to a website, you can supply this as well, although I reserve the right not to link to certain advertising/tracker-heavy websites.
\nComments are turned off on some older fics.
\n") filewrite.close() headerfooter.footerwrite("build/comments/index.html",False,local) if __name__ == "__main__": commentindex()
") if comment["site"] == "dw": if comment["registered"]: filewrite.write("" + comment["username"].replace("-","_")+ "") else: filewrite.write("anonymous") elif comment["site"] == "lj": if comment["registered"]: filewrite.write("" + comment["username"].replace("-","_")+ "") else: filewrite.write("anonymous") elif comment["site"] == "discord": filewrite.write("" + comment["username"] + "") elif comment["site"] == "ao3": if comment["registered"]: try: filewrite.write("" + comment["pseud"] + " (" + comment["username"] + ")") except: filewrite.write("" + comment["username"] + "") else: filewrite.write("" + comment["username"] + "") elif comment["site"] == "praze": try: filewrite.write("" + comment["username"] + "") except: filewrite.write(comment["username"]) try: filewrite.write(" on chapter " + str(comment["chapter"])) except: pass filewrite.write(", " + comment["date"].strftime("%Y-%m-%d")) try: filewrite.write(" [original]") except: pass filewrite.write("
\n" + comment["text"] + "
\n