Add single pages for linking to

master
trémeur 1 year ago
parent a0e4043dd7
commit e56699d480

1
.gitignore vendored

@ -3,6 +3,7 @@ build/index.html
build/*/index.html
build/ff/*/index.html
build/comments/*/index.html
build/single/*/index.html
build/feed.xml
build/files/*.html
build/files/*.pdf

@ -324,3 +324,9 @@ input#verifyage-checkbox {
width: auto;
margin: 0;
}
iframe {
height: 100vh;
width: 99%;
border: 2px solid rgb(99, 44, 44);
}

@ -11,6 +11,7 @@ import indexgen
import verifygen
import statsgen
import fandoms
import single
try:
if sys.argv[1] == "local":
@ -34,6 +35,7 @@ if __name__ == "__main__":
indexgen.indexgen(True)
verifygen.verifygen(True)
statsgen.yeargen(True)
single.allsingles(True)
else:
feed.feedgen()
masterlist.listgen()
@ -47,3 +49,4 @@ if __name__ == "__main__":
indexgen.indexgen()
verifygen.verifygen()
statsgen.yeargen()
single.allsingles()

@ -2,16 +2,249 @@ 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","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 = "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
filewrite = open(output, "a")
filewrite.write("<ul class=\"ficlinks")
# specify language if necessary
try:
if fileread.translation:
if fileread.language == "en":
filewrite.write(" english")
elif fileread.language == "fr":
filewrite.write (" french")
except:
pass
filewrite.write("\">\n")
# write html link if there is one
if fileread.html:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(ficnostring + ".html\">HTML</a></li>\n")
# write pdf link if there is one
if fileread.pdf:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(ficnostring + ".pdf\">PDF</a></li>\n")
# write epub link if there is one
if fileread.epub:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(ficnostring + ".epub\">EPUB</a></li>\n")
# write ao3 link if there is one
try:
if fileread.ao3slug:
filewrite.write("<li class=\"ao3link\"><a ")
try:
if fileread.ao3locked:
filewrite.write("class=\"locked\" ")
except:
if fileread.locked:
filewrite.write("class=\"locked\" ")
filewrite.write("href=\"https://archiveofourown.org/works/" + str(fileread.ao3slug) + "\">AO3</a></li>\n")
except:
pass
# determine if comments page
if any(item in fffandoms for item in fileread.fandom):
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
else:
timeelapsed = datetime.datetime.now() - (fileread.datewords[-1])["date"]
if timeelapsed.days < 730:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
else:
try:
if fileread.event == "ao3exchange" and (fileread.datewords[0])["date"].year > 2019:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
else:
try:
if fileread.comments:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
except:
pass
except:
try:
if fileread.comments:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
except:
pass
filewrite.write("</ul>\n")
# write links for translation if required
try:
if fileread.translation:
if transread.language == "en":
filewrite.write("<ul class=\"ficlinks english")
elif transread.language == "fr":
filewrite.write("<ul class=\"ficlinks french")
filewrite.write("\">\n")
# write html link if there is one
if fileread.html:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(translationstring + ".html\">HTML</a></li>\n")
# write pdf link if there is one
if fileread.pdf:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(translationstring + ".pdf\">PDF</a></li>\n")
# write epub link if there is one
if fileread.epub:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(translationstring + ".epub\">EPUB</a></li>\n")
# write ao3 link if there is one
try:
if fileread.ao3slug:
filewrite.write("<li class=\"ao3link\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" ")
filewrite.write("href=\"https://archiveofourown.org/works/" + str(transread.ao3slug) + "\">AO3</a></li>\n")
except:
pass
# determine if comments page required
if any(item in fffandoms for item in fileread.fandom):
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + translationstring + "/index.html")
else:
filewrite.write("/fic/comments/" + translationstring)
filewrite.write("\">comments</a></li>\n")
else:
timeelapsed = datetime.datetime.now() - (transread.datewords[-1])["date"]
if timeelapsed.days < 730:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + translationstring + "/index.html")
else:
filewrite.write("/fic/comments/" + translationstring)
filewrite.write("\">comments</a></li>\n")
else:
try:
if transread.comments:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + translationstring + "/index.html")
else:
filewrite.write("/fic/comments/" + translationstring)
filewrite.write("\">comments</a></li>\n")
except:
pass
filewrite.write("</ul>\n")
except:
pass
def ficgen(ficno,unique=False,output="output.html",local=False):
# convert to three-digit number
if ficno < 10:
@ -350,216 +583,8 @@ def ficgen(ficno,unique=False,output="output.html",local=False):
except:
if juvenilia:
filewrite.write("</p>\n")
filewrite.write("<ul class=\"ficlinks")
# specify language if necessary
try:
if fileread.translation:
if fileread.language == "en":
filewrite.write(" english")
elif fileread.language == "fr":
filewrite.write (" french")
except:
pass
filewrite.write("\">\n")
# write html link if there is one
if fileread.html:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(ficnostring + ".html\">HTML</a></li>\n")
# write pdf link if there is one
if fileread.pdf:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(ficnostring + ".pdf\">PDF</a></li>\n")
# write epub link if there is one
if fileread.epub:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(ficnostring + ".epub\">EPUB</a></li>\n")
# write ao3 link if there is one
try:
if fileread.ao3slug:
filewrite.write("<li class=\"ao3link\"><a ")
try:
if fileread.ao3locked:
filewrite.write("class=\"locked\" ")
except:
if fileread.locked:
filewrite.write("class=\"locked\" ")
filewrite.write("href=\"https://archiveofourown.org/works/" + str(fileread.ao3slug) + "\">AO3</a></li>\n")
except:
pass
# determine if comments page
if any(item in fffandoms for item in fileread.fandom):
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
else:
timeelapsed = datetime.datetime.now() - (fileread.datewords[-1])["date"]
if timeelapsed.days < 730:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
else:
try:
if fileread.event == "ao3exchange" and (fileread.datewords[0])["date"].year > 2019:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
else:
try:
if fileread.comments:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
except:
pass
except:
try:
if fileread.comments:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + ficnostring + "/index.html")
else:
filewrite.write("/fic/comments/" + ficnostring)
filewrite.write("\">comments</a></li>\n")
except:
pass
filewrite.write("</ul>\n")
# write links for translation if required
try:
if fileread.translation:
if transread.language == "en":
filewrite.write("<ul class=\"ficlinks english")
elif transread.language == "fr":
filewrite.write("<ul class=\"ficlinks french")
filewrite.write("\">\n")
# write html link if there is one
if fileread.html:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(translationstring + ".html\">HTML</a></li>\n")
# write pdf link if there is one
if fileread.pdf:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(translationstring + ".pdf\">PDF</a></li>\n")
# write epub link if there is one
if fileread.epub:
filewrite.write("<li class=\"prazelink\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/secret/")
else:
filewrite.write("/fic/secret/")
else:
if local:
filewrite.write("href=\"/home/mdd/Documents/drive/proj/fic-archive/build/files/")
else:
filewrite.write("href=\"/fic/files/")
filewrite.write(translationstring + ".epub\">EPUB</a></li>\n")
# write ao3 link if there is one
try:
if fileread.ao3slug:
filewrite.write("<li class=\"ao3link\"><a ")
if fileread.locked:
filewrite.write("class=\"locked\" ")
filewrite.write("href=\"https://archiveofourown.org/works/" + str(transread.ao3slug) + "\">AO3</a></li>\n")
except:
pass
# determine if comments page required
if any(item in fffandoms for item in fileread.fandom):
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + translationstring + "/index.html")
else:
filewrite.write("/fic/comments/" + translationstring)
filewrite.write("\">comments</a></li>\n")
else:
timeelapsed = datetime.datetime.now() - (transread.datewords[-1])["date"]
if timeelapsed.days < 730:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + translationstring + "/index.html")
else:
filewrite.write("/fic/comments/" + translationstring)
filewrite.write("\">comments</a></li>\n")
else:
try:
if transread.comments:
filewrite.write("<li class=\"prazelink\"><a href=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/comments/" + translationstring + "/index.html")
else:
filewrite.write("/fic/comments/" + translationstring)
filewrite.write("\">comments</a></li>\n")
except:
pass
filewrite.write("</ul>\n")
except:
pass
filewrite.close()
linkgen(ficno,output,local)
filewrite = open(output, "a")
filewrite.write("</div>\n")
filewrite.close()

@ -0,0 +1,92 @@
import datetime, os, shutil
from importlib import import_module
import headerfooter
import makeheader
"""
Code to generate standalone fic pages
"""
def singlepage(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 unlocked
try:
if fileread.locked:
singlestatus = False
else:
singlestatus = True
except:
singlestatus = True
if singlestatus:
singlepath = "build/single/" + ficnostring
if not os.path.isdir(singlepath):
os.mkdir(singlepath)
if os.path.exists(singlepath + "/index.html"):
os.remove(singlepath + "/index.html")
# write to output file
output = singlepath + "/index.html"
headerfooter.headerwrite(output,"Fic no. " + ficnostring,"Fic no. <span id=\"ficno\">" + ficnostring + "</span>","",False,local)
try:
if fileread.original:
makeheader.ficgen(fileread.original,False,output,local)
else:
makeheader.ficgen(ficno,False,output,local)
except:
makeheader.ficgen(ficno,False,output,local)
filewrite = open(output, "a")
filewrite.write("<iframe src=\"")
if local:
filewrite.write("/home/mdd/Documents/drive/proj/fic-archive/build/files/" + ficnostring + ".html")
else:
filewrite.write("/fic/files/" + ficnostring + ".html")
filewrite.write("\"></iframe>\n<div class=\"fic\">\n")
filewrite.close()
try:
if fileread.original:
makeheader.linkgen(fileread.original,output,local)
else:
makeheader.linkgen(ficno,output,local)
except:
makeheader.linkgen(ficno,output,local)
filewrite = open(output, "a")
filewrite.write("</div>\n")
filewrite.close()
headerfooter.footerwrite(output,False,local)
"""
Generate all single pages
"""
def allsingles(local=False):
for filename in os.listdir("build/single"):
filepath = os.path.join("build/single", 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"):
singlepage(ficcount,"originalsmeta",local)
elif os.path.exists("translationsmeta/" + ficcountstring + ".py"):
singlepage(ficcount,"translationsmeta",local)
if __name__ == "__main__":
allsingles()
Loading…
Cancel
Save