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"] """ 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 = "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("

Leave a comment

\n

Comments will be posted manually; please expect a delay between submitting your comment and seeing it below!

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

Archived comments

\n

If you left one of these comments and would like it to be removed from the archive, please email me.

\n

My replies are included only if they were originally posted on this site.

\n") for comment in fileread.comments: filewrite.write("
\n

") if comment["site"] == "dw": if comment["registered"]: filewrite.write("\"[personal" + comment["username"].replace("-","_")+ "") else: filewrite.write("\"[personalanonymous") elif comment["site"] == "lj": if comment["registered"]: filewrite.write("\"[personal" + comment["username"].replace("-","_")+ "") else: filewrite.write("\"[personalanonymous") elif comment["site"] == "ao3": if comment["registered"]: try: filewrite.write("\"[archiveofourown.org" + comment["pseud"] + " (" + comment["username"] + ")") except: filewrite.write("\"[archiveofourown.org" + comment["username"] + "") else: filewrite.write("\"[archiveofourown.org" + 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
\n") except: pass if fffandom or timeelapsed.days < 730: filewrite.write("\n") filewrite.close() headerfooter.footerwrite(commentspath + "/index.html",False,local) """ Generate all comment pages """ def allcomments(local=False): for filename in os.listdir("build/comments"): filepath = os.path.join("build/comments", filename) if os.path.isfile(filepath): os.unlink(filepath) elif os.path.isdir(filepath): shutil.rmtree(filepath) 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"): commentpage(ficcount,"originalsmeta",local) elif os.path.exists("translationsmeta/" + ficcountstring + ".py"): commentpage(ficcount,"translationsmeta",local) if __name__ == "__main__": allcomments() """ Generate comments index page """ def commentindex(local=False): # delete existing file if os.path.exists("build/comments/index.html"): os.remove("build/comments/index.html") # write header headerfooter.headerwrite("build/comments/index.html","Comments","Comments","",False,local) filewrite = open("build/comments/index.html", "a") filewrite.write("

Comments 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 and the only place I really “advertise” it is Dreamwidth.

\n

You can leave comments on the relevant comment pages for each fic. If you’d like notification of any reply, please leave your email address. If you’d like a link from your pseudonym to a website, you can supply this as well. I’ll happily link to personal websites, Dreamwidth profiles, and (at least for now) AO3 profiles; I’m unlikely to include links to for-profit social media websites, Carrd, or Patreon.

\n

Comments are turned off on any fic over two years old unless it’s in a Final Fantasy fandom. On AO3, comments are turned off on all fics over two years old, unless they were written for AO3-hosted gift exchanges in 2020 or later.

\n") filewrite.close() headerfooter.footerwrite("build/comments/index.html",False,local) if __name__ == "__main__": commentindex()