From a6a5e0a87e6bb4d7c1d9054f4bc4fbed3e9fae0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?tr=C3=A9meur?=
Date: Tue, 27 Jun 2023 19:35:00 +0100
Subject: [PATCH] Add page to display all fics by fandom
---
build/byfandom/.gitkeep | 0
fandoms.py | 120 ++++++++++++++++++++++++++++++++++++++++
generate.py | 3 +
indexgen.py | 9 ++-
masterlist.py | 2 +-
5 files changed, 131 insertions(+), 3 deletions(-)
create mode 100644 build/byfandom/.gitkeep
create mode 100644 fandoms.py
diff --git a/build/byfandom/.gitkeep b/build/byfandom/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/fandoms.py b/fandoms.py
new file mode 100644
index 0000000..75ed142
--- /dev/null
+++ b/fandoms.py
@@ -0,0 +1,120 @@
+import datetime, os
+from importlib import import_module
+
+import makeheader
+import headerfooter
+
+def fandomlist(local=False):
+ # delete existing file
+ if os.path.exists("build/byfandom/index.html"):
+ os.remove("build/byfandom/index.html")
+ # write header
+ headerfooter.headerwrite("build/byfandom/index.html","Fics by fandom","Fics by fandom","On this page, you’ll find basically everything I’ve ever written that is a. fanfiction and b. extant, grouped by fandom and then sorted newest to oldest; quality may vary. RPF and things I wrote before 2020 require a username and password to access.
",False,local)
+ # get list of fandoms
+ fandoms = []
+ 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"):
+ ficfile = "originalsmeta." + ficcountstring
+ fileread = import_module(ficfile)
+ try:
+ if fileread.revealdate > datetime.datetime.now():
+ revealed = False
+ else:
+ revealed = True
+ except:
+ revealed = True
+ if revealed == True:
+ for fandom in fileread.fandom:
+ fandoms.append(fandom)
+ newlist = []
+ for fandom in fandoms:
+ if fandom not in newlist:
+ newlist.append(fandom)
+ fandomlist = []
+ for fandom in newlist:
+ if "FF" in fandom:
+ if fandom == "FFX":
+ newfandom = "FF10"
+ elif len(fandom) == 3:
+ newfandom = "FF0" + fandom[-1]
+ else:
+ newfandom = fandom
+ fandomlist.append({"searchname":fandom,"sortname":newfandom.replace("FF","Final Fantasy "),"displayname":fandom.replace("FF","Final Fantasy ")})
+ else:
+ fandomlist.append({"searchname":fandom,"sortname":fandom,"displayname":fandom})
+ fandomlist = sorted(fandomlist, key=lambda d: d["sortname"])
+ for fandom in fandomlist:
+ fandomfics = []
+ # check which fics are in the fandom
+ 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"):
+ countfile = "originalsmeta." + ficcountstring
+ fileread = import_module(countfile)
+ try:
+ if fileread.revealdate > datetime.datetime.now():
+ revealed = False
+ else:
+ revealed = True
+ except:
+ revealed = True
+ if revealed == True:
+ if fandom["searchname"] in fileread.fandom:
+ fandomfics.append(ficcount)
+ firstfic = fandomfics[-1]
+ if firstfic < 10:
+ firstficstring = "00" + str(firstfic)
+ elif firstfic < 100:
+ firstficstring = "0" + str(firstfic)
+ else:
+ firstficstring = str(firstfic)
+ firstfile = "originalsmeta." + firstficstring
+ firstread = import_module(firstfile)
+ firstyear = (firstread.datewords[0])["date"].year
+ lastfic = fandomfics[0]
+ if lastfic < 10:
+ lastficstring = "00" + str(lastfic)
+ elif lastfic < 100:
+ lastficstring = "0" + str(lastfic)
+ else:
+ lastficstring = str(lastfic)
+ lastfile = "originalsmeta." + lastficstring
+ lastread = import_module(lastfile)
+ lastyear = (lastread.datewords[0])["date"].year
+ if lastyear == firstyear:
+ yearstring = str(firstyear)
+ else:
+ yearstring = str(firstyear) + "–" + str(lastyear)
+ # write details element
+ output = "build/byfandom/index.html"
+ filewrite = open(output, "a")
+ filewrite.write("" + fandom["displayname"] + " (" + str(len(fandomfics)) + " fic")
+ if len(fandomfics) > 1:
+ filewrite.write("s")
+ filewrite.write(", " + yearstring + ")
\n")
+ filewrite.close()
+ for fic in fandomfics:
+ makeheader.ficgen(fic,False,output,local)
+ filewrite = open(output, "a")
+ filewrite.write(" \n")
+ filewrite.close()
+ # write footer
+ headerfooter.footerwrite("build/byfandom/index.html",False,local)
+
+if __name__ == "__main__":
+ fandomlist(True)
diff --git a/generate.py b/generate.py
index a9b9ac9..18b93e4 100644
--- a/generate.py
+++ b/generate.py
@@ -9,6 +9,7 @@ import events
import indexgen
import verifygen
import statsgen
+import fandoms
try:
if sys.argv[1] == "local":
@@ -22,6 +23,7 @@ if __name__ == "__main__":
if local == True:
feed.feedgen(True)
masterlist.listgen(True)
+ fandoms.fandomlist(True)
commentpage.allcomments(True)
commentpage.commentindex(True)
characters.charlist(True)
@@ -33,6 +35,7 @@ if __name__ == "__main__":
else:
feed.feedgen()
masterlist.listgen()
+ fandoms.fandomlist()
commentpage.allcomments()
commentpage.commentindex()
characters.charlist()
diff --git a/indexgen.py b/indexgen.py
index 2295034..8b98ce1 100644
--- a/indexgen.py
+++ b/indexgen.py
@@ -17,12 +17,17 @@ def indexgen(local=False):
filewrite.write("\">here.
\nYou can also subscribe to the RSS feed to be notified of new fics and updates to existing ones.
\n