From 663cac35b954de8f69539b11529c5d396446ea17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Mon, 20 Nov 2023 21:26:41 +0000 Subject: [PATCH] Sort fics properly --- characters.py | 25 +++++++++++++++++++++---- events.py | 12 ++++++++---- fandoms.py | 7 ++++++- masterlist.py | 14 +++++++++++++- ships.py | 13 +++++++++++-- 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/characters.py b/characters.py index 91d00e8..5be6405 100644 --- a/characters.py +++ b/characters.py @@ -90,26 +90,27 @@ def charlist(local=False): except: revealed = True if revealed == True: + ficdict = {"thefic":ficcount,"thedate":(fileread.datewords[-1])["date"]} if searchfandom in fileread.fandom: # append to lists try: if character in fileread.charpov: - povcount.append(ficcount) + povcount.append(ficdict) except: pass try: if character in fileread.charmain: - maincount.append(ficcount) + maincount.append(ficdict) except: pass try: if character in fileread.charsecondary: - secondarycount.append(ficcount) + secondarycount.append(ficdict) except: pass try: if character in fileread.charmention: - mentioncount.append(ficcount) + mentioncount.append(ficdict) except: pass # write details element @@ -132,25 +133,41 @@ def charlist(local=False): filewrite = open(output, "a") filewrite.write("

POV character

\n") filewrite.close() + povcount = sorted(povcount,key=lambda d: d["thedate"],reverse=True) + newpov = [] for fic in povcount: + newpov.append(fic["thefic"]) + for fic in newpov: makeheader.ficgen(fic,False,output,local) if len(maincount) > 0: filewrite = open(output, "a") filewrite.write("

Main character

\n") filewrite.close() + maincount = sorted(maincount,key=lambda d: d["thedate"],reverse=True) + newmain = [] for fic in maincount: + newmain.append(fic["thefic"]) + for fic in newmain: makeheader.ficgen(fic,False,output,local) if len(secondarycount) > 0: filewrite = open(output, "a") filewrite.write("

Secondary character

\n") filewrite.close() + secondarycount = sorted(secondarycount,key=lambda d: d["thedate"],reverse=True) + newsecondary = [] for fic in secondarycount: + newsecondary.append(fic["thefic"]) + for fic in newsecondary: makeheader.ficgen(fic,False,output,local) if len(mentioncount) > 0: filewrite = open(output, "a") filewrite.write("

Mentioned

\n") filewrite.close() + mentioncount = sorted(mentioncount,key=lambda d: d["thedate"],reverse=True) + newmention = [] for fic in mentioncount: + newmention.append(fic["thefic"]) + for fic in newmention: makeheader.ficgen(fic,False,output,local) filewrite = open(output, "a") filewrite.write("\n") diff --git a/events.py b/events.py index 00e0614..8dd8bda 100644 --- a/events.py +++ b/events.py @@ -70,7 +70,7 @@ def eventlist(local=False): if revealed == True: try: if fileread.eventname == theevent: - evententries.append({"ficno":ficcount,"year":(fileread.datewords[0])["date"].year,"fandom":fileread.fandom}) + evententries.append({"ficno":ficcount,"year":(fileread.datewords[0])["date"].year,"fandom":fileread.fandom,"update":(fileread.datewords[-1])["date"]}) except: pass eventfandoms = [] @@ -102,13 +102,17 @@ def eventlist(local=False): yearlist = [] for entry in evententries: if int(entry["year"]) == startyear: - yearlist.append(entry["ficno"]) + ficdict = {"thefic":entry["ficno"],"thedate":entry["update"]} + yearlist.append(ficdict) if len(yearlist) > 0: - yearlist = sorted(yearlist) + yearlist = sorted(yearlist,key=lambda d: d["thedate"]) + newyear = [] + for fic in yearlist: + newyear.append(fic["thefic"]) filewrite = open(output, "a") filewrite.write("

" + str(startyear) + "

\n") filewrite.close() - for fic in yearlist: + for fic in newyear: makeheader.ficgen(fic,False,output,local) filewrite = open(output, "a") filewrite.write("\n") diff --git a/fandoms.py b/fandoms.py index 9134e00..6077efa 100644 --- a/fandoms.py +++ b/fandoms.py @@ -53,6 +53,7 @@ def fandomlist(local=False): fandomlist = sorted(fandomlist, key=lambda d: d["sortname"]) for fandom in fandomlist: fandomfics = [] + sortfics = [] # check which fics are in the fandom ficcount = 500 while ficcount > 0: @@ -75,7 +76,11 @@ def fandomlist(local=False): revealed = True if revealed == True: if fandom["searchname"] in fileread.fandom: - fandomfics.append(ficcount) + ficdict = {"thefic":ficcount,"thedate":(fileread.datewords[-1])["date"]} + sortfics.append(ficdict) + thefics = sorted(sortfics,key=lambda d: d["thedate"],reverse=True) + for fic in thefics: + fandomfics.append(fic["thefic"]) firstfic = fandomfics[-1] if firstfic < 10: firstficstring = "00" + str(firstfic) diff --git a/masterlist.py b/masterlist.py index d2f6b93..00e56f9 100644 --- a/masterlist.py +++ b/masterlist.py @@ -16,6 +16,7 @@ def listgen(local=False): headerfooter.headerwrite("build/masterlist/index.html","Masterlist","Fic masterlist","

On this page, from newest to oldest, you’ll find basically everything I’ve ever written that is a. fanfiction and b. extant; quality may vary. Some fics, such as things I wrote before 2020, require a username and password to access.

",False,local) # write fic divs ficcount = 500 + sortfics = [] while ficcount > 0: ficcount -= 1 if ficcount < 10: @@ -25,7 +26,18 @@ def listgen(local=False): else: ficcountstring = str(ficcount) if os.path.exists("originalsmeta/" + ficcountstring + ".py"): - makeheader.ficgen(ficcount,True,"build/masterlist/index.html",local) + ficfile = "originalsmeta." + ficcountstring + fileread = import_module(ficfile) + try: + if fileread.revealdate <= datetime.datetime.now(): + ficdict = {"thefic":ficcount,"thedate":(fileread.datewords[-1])["date"]} + sortfics.append(ficdict) + except: + ficdict = {"thefic":ficcount,"thedate":(fileread.datewords[-1])["date"]} + sortfics.append(ficdict) + thefics = sorted(sortfics, key=lambda d: d["thedate"],reverse=True) + for fic in thefics: + makeheader.ficgen(fic["thefic"],True,"build/masterlist/index.html",local) # write footer headerfooter.footerwrite("build/masterlist/index.html",False,local) diff --git a/ships.py b/ships.py index 708f102..0b15b0e 100644 --- a/ships.py +++ b/ships.py @@ -78,13 +78,14 @@ def shiplist(local=False): except: revealed = True if revealed == True: + ficdict = {"thefic":ficcount,"thedate":(fileread.datewords[-1])["date"]} if searchfandom in fileread.fandom: # append to lists try: if fileread.ship[0] == ship: - maincount.append(ficcount) + maincount.append(ficdict) elif ship in fileread.ship: - secondarycount.append(ficcount) + secondarycount.append(ficdict) except: pass # write details element @@ -103,13 +104,21 @@ def shiplist(local=False): filewrite = open(output, "a") filewrite.write("

Main ship

\n") filewrite.close() + maincount = sorted(maincount,key=lambda d: d["thedate"],reverse=True) + newmain = [] for fic in maincount: + newmain.append(fic["thefic"]) + for fic in newmain: makeheader.ficgen(fic,False,output,local) if len(secondarycount) > 0: filewrite = open(output, "a") filewrite.write("

Secondary ship

\n") filewrite.close() + secondarycount = sorted(secondarycount,key=lambda d: d["thedate"],reverse=True) + newsecondary = [] for fic in secondarycount: + newsecondary.append(fic["thefic"]) + for fic in newsecondary: makeheader.ficgen(fic,False,output,local) filewrite = open(output, "a") filewrite.write("\n")