|
|
|
@ -0,0 +1,165 @@
|
|
|
|
|
import requests, datetime, os, re
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
# presumably needed for nsfw content
|
|
|
|
|
login_url = "https://www.archiveofourown.org/users/login"
|
|
|
|
|
data = {
|
|
|
|
|
"user": "translinkni",
|
|
|
|
|
"password": "notreallyanapi"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if os.path.exists("ficheader.html"):
|
|
|
|
|
os.remove("ficheader.html")
|
|
|
|
|
|
|
|
|
|
thefile = open("ficheader.html", "a")
|
|
|
|
|
|
|
|
|
|
with requests.Session() as s:
|
|
|
|
|
response = s.post(login_url , data)
|
|
|
|
|
print("Work ID: ")
|
|
|
|
|
id = input()
|
|
|
|
|
url = "https://archiveofourown.org/works/" + str(id)
|
|
|
|
|
ficpage = s.get(url)
|
|
|
|
|
ficsoup = BeautifulSoup(ficpage.content, "html.parser")
|
|
|
|
|
rating = ficsoup.find("dd", class_="rating").text.strip()
|
|
|
|
|
if str(rating) == "General Audiences":
|
|
|
|
|
prazerating = "g"
|
|
|
|
|
elif str(rating) == "Teen And Up Audiences":
|
|
|
|
|
prazerating = "t"
|
|
|
|
|
elif str(rating) == "Mature":
|
|
|
|
|
prazerating = "m"
|
|
|
|
|
elif str(rating) == "Explicit":
|
|
|
|
|
prazerating = "e"
|
|
|
|
|
warningheader = ficsoup.find("dd", {"class":["warning", "warnings"]})
|
|
|
|
|
rawwarnings = warningheader.find_all("li")
|
|
|
|
|
warnings = []
|
|
|
|
|
for c in rawwarnings:
|
|
|
|
|
warning = c.text
|
|
|
|
|
warnings.append(str(warning))
|
|
|
|
|
prazewarnings = []
|
|
|
|
|
if "No Archive Warnings Apply" in warnings:
|
|
|
|
|
prazewarn = 0
|
|
|
|
|
elif "Creator Chose Not To Use Archive Warnings" in warnings:
|
|
|
|
|
prazewarn = 1
|
|
|
|
|
prazewarnings.append("miscellaneous")
|
|
|
|
|
else:
|
|
|
|
|
prazewarn = 1
|
|
|
|
|
if "Major Character Death" in warnings:
|
|
|
|
|
prazewarnings.append("character death")
|
|
|
|
|
if "Underage" in warnings:
|
|
|
|
|
prazewarnings.append("underage")
|
|
|
|
|
categoryheader = ficsoup.find("dd", {"class":["category", "categories"]})
|
|
|
|
|
rawcategories = categoryheader.find_all("li")
|
|
|
|
|
categories = []
|
|
|
|
|
for c in rawcategories:
|
|
|
|
|
category = c.text
|
|
|
|
|
categories.append(str(category))
|
|
|
|
|
prazegenre = []
|
|
|
|
|
if "Gen" in categories:
|
|
|
|
|
prazegenre.append("gen")
|
|
|
|
|
if "M/M" in categories:
|
|
|
|
|
prazegenre.append("slash")
|
|
|
|
|
if "F/M" in categories:
|
|
|
|
|
prazegenre.append("het")
|
|
|
|
|
if "F/F" in categories:
|
|
|
|
|
prazegenre.append("femslash")
|
|
|
|
|
if "Multi" in categories:
|
|
|
|
|
prazegenre.append("poly")
|
|
|
|
|
fandomheader = ficsoup.find("dd", {"class":["fandom", "fandoms"]})
|
|
|
|
|
rawfandoms = fandomheader.find_all("li")
|
|
|
|
|
fandoms = []
|
|
|
|
|
for c in rawfandoms:
|
|
|
|
|
rawfandom = str(c.text)
|
|
|
|
|
if rawfandom == "Final Fantasy VI":
|
|
|
|
|
fandom = "FF6"
|
|
|
|
|
elif rawfandom == "Compilation of Final Fantasy VII":
|
|
|
|
|
fandom = "FF7"
|
|
|
|
|
elif rawfandom == "Crisis Core: Final Fantasy VII":
|
|
|
|
|
fandom = "FF7 Crisis Core"
|
|
|
|
|
elif rawfandom == "Final Fantasy VII (Video Game 1997)":
|
|
|
|
|
fandom = "FF7"
|
|
|
|
|
elif rawfandom == "Final Fantasy VII Remake (Video Game 2020)":
|
|
|
|
|
fandom = "FF7R"
|
|
|
|
|
elif rawfandom == "Final Fantasy X":
|
|
|
|
|
fandom = "FFX"
|
|
|
|
|
elif rawfandom == "Final Fantasy X Series":
|
|
|
|
|
fandom = "FFX"
|
|
|
|
|
elif rawfandom == "Final Fantasy X-2":
|
|
|
|
|
fandom = "FFX-2"
|
|
|
|
|
elif rawfandom == "Final Fantasy IX":
|
|
|
|
|
fandom = "FF9"
|
|
|
|
|
else:
|
|
|
|
|
fandom = rawfandom
|
|
|
|
|
fandoms.append(fandom)
|
|
|
|
|
characterheader = ficsoup.find("dd", {"class":["character", "characters"]})
|
|
|
|
|
rawcharacters = characterheader.find_all("li")
|
|
|
|
|
characters = []
|
|
|
|
|
for c in rawcharacters:
|
|
|
|
|
rawcharacter = str(c.text)
|
|
|
|
|
cleancharacter = re.sub(r" \(.*\)","",rawcharacter)
|
|
|
|
|
if cleancharacter == "Locke Cole":
|
|
|
|
|
character = "Locke"
|
|
|
|
|
elif cleancharacter == "Macías \"Mash\" Rene Figaro | Sabin Rene Figaro":
|
|
|
|
|
character = "Sabin"
|
|
|
|
|
elif cleancharacter == "Celes Chere":
|
|
|
|
|
character = "Celes"
|
|
|
|
|
elif cleancharacter == "Edgar Roni Figaro":
|
|
|
|
|
character = "Edgar"
|
|
|
|
|
elif cleancharacter == "Tina Branford | Terra Branford":
|
|
|
|
|
character = "Terra"
|
|
|
|
|
elif cleancharacter == "Original Characters":
|
|
|
|
|
character = "OCs"
|
|
|
|
|
elif cleancharacter == "Original Male Character":
|
|
|
|
|
character = "OMC"
|
|
|
|
|
elif cleancharacter == "Original Female Character":
|
|
|
|
|
character = "OFC"
|
|
|
|
|
else:
|
|
|
|
|
character = cleancharacter
|
|
|
|
|
characters.append(str(character))
|
|
|
|
|
date = ficsoup.find("dd", class_="published").text
|
|
|
|
|
prazedate = datetime.datetime.strptime(str(date), "%Y-%m-%d").strftime("%-d %B %Y")
|
|
|
|
|
words = ficsoup.find("dd", class_="words").text
|
|
|
|
|
title = ficsoup.find("h2", class_="title").text.strip()
|
|
|
|
|
summaryheader = ficsoup.find("div", class_="summary")
|
|
|
|
|
summary = summaryheader.find("blockquote")
|
|
|
|
|
notesheader = ficsoup.find("div", class_="notes")
|
|
|
|
|
try:
|
|
|
|
|
rawnotes = str(notesheader.find("blockquote"))
|
|
|
|
|
except:
|
|
|
|
|
rawnotes = 0
|
|
|
|
|
if rawnotes:
|
|
|
|
|
notesa = re.sub(r" rel=\"nofollow\"","",rawnotes)
|
|
|
|
|
notesb = re.sub(r"alt=\"\[community profile\]\"","alt=\"[community profile]\" style=\"vertical-align: text-bottom; border: 0; padding-right: 1px;\"",notesa)
|
|
|
|
|
notesc = re.sub(r"alt=\"\[personal profile\]\"","alt=\"[personal profile]\" style=\"vertical-align: text-bottom; border: 0; padding-right: 1px;\"",notesb)
|
|
|
|
|
notesd = re.sub(r"</p><p>\n<small><b>Standard note for 3sf fills:</b> I’m aware that some AO3 users may not consider prompt fills “gifts”, and will take no offence if the gift is refused!</small>","",notesc)
|
|
|
|
|
notes = re.sub(r"\n</p>","</p>",notesd)
|
|
|
|
|
else:
|
|
|
|
|
notes = 0
|
|
|
|
|
masterlist = s.get("https://tre.praze.net/fic/master.html")
|
|
|
|
|
mastersoup = BeautifulSoup(masterlist.content, "html.parser")
|
|
|
|
|
ficno = int(mastersoup.find("span", class_="ficno").text.strip()) + 1
|
|
|
|
|
thefile.write("<div class=\"fic\" id=\"fic" + str(ficno) + "\">\n")
|
|
|
|
|
thefile.write(" <h1><span class=\"ficno\">" + str(ficno) + "</span> <span class=\"fictitle\">" + title + "</span></h1>\n")
|
|
|
|
|
thefile.write(" <ul class=\"ficmeta\">\n")
|
|
|
|
|
thefile.write(" <li class=\"ficdate\">" + prazedate + "</li>\n")
|
|
|
|
|
thefile.write(" <li class=\"wordcount\">" + str(words) + "</li>\n")
|
|
|
|
|
if prazerating == "g":
|
|
|
|
|
thefile.write(" <li class=\"rating\"><span class=\"" + prazerating + "\"/></li>\n")
|
|
|
|
|
else:
|
|
|
|
|
thefile.write(" <li class=\"rating\"><span class=\"" + prazerating + "\"/> ()</li>\n")
|
|
|
|
|
thefile.write(" <li class=\"fandom\">" + "/".join(fandoms) + "</li>\n")
|
|
|
|
|
thefile.write(" <li class=\"characters\">" + ", ".join(characters) + "</li>\n")
|
|
|
|
|
thefile.write(" <li class=\"genre\">" + ", ".join(prazegenre) + "</li>\n")
|
|
|
|
|
if prazewarn:
|
|
|
|
|
thefile.write(" <li class=\"warnings\">" + ", ".join(prazewarnings) + "</li>\n")
|
|
|
|
|
thefile.write(" </ul>\n")
|
|
|
|
|
thefile.write(" <p class=\"summary\">" + str(summary)[34:-18] + "</p>\n")
|
|
|
|
|
if notes:
|
|
|
|
|
thefile.write(" <p class=\"note\">" + str(notes)[34:-18] + "</p>\n")
|
|
|
|
|
thefile.write(" <ul class=\"ficlinks\">\n")
|
|
|
|
|
thefile.write(" <li class=\"ao3link\"><a href=\"https://archiveofourown.org/works/" + str(id) + "\">AO3</a></li>\n")
|
|
|
|
|
thefile.write(" <li class=\"prazelink\"><a href=\"files/" + str(ficno) + ".html\">HTML</a></li>\n")
|
|
|
|
|
thefile.write(" <li class=\"prazelink\"><a href=\"files/" + str(ficno) + ".pdf\">PDF</a></li>\n")
|
|
|
|
|
thefile.write(" <li class=\"prazelink\"><a href=\"files/" + str(ficno) + ".epub\">EPUB</a></li>\n")
|
|
|
|
|
thefile.write(" </ul>\n")
|
|
|
|
|
thefile.write("</div>\n")
|
|
|
|
|
print("File saved to " + str(os.path.abspath("ficheader.html")))
|