notes/identify.py

164 lines
12 KiB
Python

import secrets
import orgparse,os,re
from datetime import datetime
thisyear = datetime.now().strftime("%Y")
year = 1993
concernedfiles = []
while year < int(thisyear) + 1:
month = 0
while month < 13:
if month < 10:
strmonth = "0" + str(month)
else:
strmonth = str(month)
recdir = str(year) + "/" + strmonth + "/"
fullpath = secrets.orgpath + recdir
if os.path.exists(fullpath):
for file in sorted(os.listdir(fullpath)):
filename = fullpath + str(file)
if filename.endswith(".org"):
concernedfiles.append(filename)
month = month + 1
year = year + 1
posts = []
rss = []
for file in concernedfiles:
filedate = file[-14:-4]
parsefile = orgparse.load(file)
try:
for node in parsefile.children:
if node.heading == "site":
for post in node.children:
if "update" in post.tags:
thedict = {}
thedict["title"] = post.heading
thedict["desc"] = post.get_body(format="raw")
thedict["date"] = filedate
try:
thedict["time"] = post.properties["time"]
except:
pass
try:
if post.properties["url"] == "/index.html":
thedict["url"] = "https://tre.praze.net"
else:
thedict["url"] = "https://tre.praze.net" + post.properties["url"]
except:
pass
try:
thedict["categories"] = post.properties["categories"].split(",")
except:
pass
rss.append(thedict)
elif "post" in post.tags:
writefile = open(filedate + ".org","w")
writefile.write("#+TITLE: " + post.heading + "\n#+REALTITLE: " + post.properties["realtitle"] + "\n#+OGDESC: " + post.properties["ogdesc"]+ "\n#+CATEGORY: " + post.properties["category"] + "\n#+COMMENTS: " + post.properties["comments"] + "\n")
try:
writefile.write("#+OP: " + post.properties["op"] + "\n")
except:
pass
writefile.write(post.get_body(format="raw") + "\n")
try:
for child in post.children:
if "noexport" not in child.tags:
if child.heading == "yes":
writefile.write("\n")
else:
writefile.write("* " + child.heading + "\n")
writefile.write(child.get_body(format="raw") + "\n")
except:
pass
writefile.close()
thedict = {}
thedict["title"] = post.heading
thedict["real"] = post.properties["realtitle"]
thedict["date"] = filedate
try:
thedict["time"] = post.properties["time"]
except:
pass
if post.properties["category"] == "reminding myself how to do stuff":
thedict["category"] = "techbro"
elif post.properties["category"] == "writing notes":
thedict["category"] = "writing"
elif post.properties["category"] == "journal memes":
thedict["category"] = "meme"
elif post.properties["category"] == "revues":
thedict["category"] = "revue"
else:
thedict["category"] = post.properties["category"]
try:
thedict["media"] = post.properties["type"]
except:
pass
posts.append(thedict)
rss.append(thedict)
except:
pass
posts = sorted(posts,key=lambda d: d["date"],reverse=True)
for entry in rss:
try:
entry["combinedate"] = entry["date"] + " " + entry["time"]
except:
entry["combinedate"] = entry["date"] + " 03:00:00"
try:
if entry["category"]:
postcats = []
postcats.append("post")
postcats.append(entry["category"])
entry["categories"] = postcats
except:
pass
try:
if "post" in entry["categories"]:
entry["url"] = "https://tre.praze.net/notes/" + re.sub("-","",entry["date"])
entry["desc"] = "placeholder"
except:
pass
try:
if entry["real"]:
entry["real"] = re.sub("<[^<]+?>","",entry["real"])
except:
pass
entry["rssdatetime"] = datetime.strftime((datetime.strptime(entry["combinedate"],"%Y-%m-%d %H:%M:%S")),"%a, %d %b %Y %H:%M:%S +0000")
rss = sorted(rss,key=lambda d: d["combinedate"],reverse=True)
writersslist = open("therss.py","w")
writersslist.write("rss = " + str(rss))
writersslist.close()
writeindex = open("build/index.html","w")
writeindex.write("<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<title>praze • Notes</title>\n<meta property=\"og:title\" content=\"praze • Notes\">\n<meta property=\"og:type\" content=\"website\">\n<meta property=\"og:image\" content=\"https://tre.praze.net/ab.png\">\n<meta property=\"og:url\" content=\"https://tre.praze.net/notes\">\n<meta name=\"description\" property=\"og:description\" content=\"Index of notes.\">\n<meta property=\"og:locale\" content=\"en_GB\">\n<meta property=\"og:site_name\" content=\"tre.praze.net\">\n<meta name=\"fediverse:creator\" content=\"@tre@praze.net\">\n<link rel=\"stylesheet\" href=\"/new.css\">\n<link rel=\"me\" href=\"https://kes.praze.net/@tre\">\n<link rel=\"alternate\" type=\"application/rss+xml\" title=\"tre.praze.net\" href=\"/feed.xml\">\n<meta name=\"theme-color\" content=\"#f2f2f2\" />\n<style>\nli:has(a[href=\"\"]) {\ndisplay: none;\n}\n\n[value=\"meme\"]:checked ~ ul#noteslist li[data-category=\"meme\"],\n[value=\"month\"]:checked ~ ul#noteslist li[data-category=\"month\"],\n[value=\"techbro\"]:checked ~ ul#noteslist li[data-category=\"techbro\"],\n[value=\"revue\"]:checked ~ ul#noteslist li[data-category=\"revue\"],\n[value=\"tumblr\"]:checked ~ ul#noteslist li[data-category=\"tumblr\"],\n[value=\"writing\"]:checked ~ ul#noteslist li[data-category=\"writing\"]\n{\ndisplay:list-item;\n}\n\n[value=\"meme\"]:not(:checked) ~ ul#noteslist li[data-category=\"meme\"],\n[value=\"month\"]:not(:checked) ~ ul#noteslist li[data-category=\"month\"],\n[value=\"techbro\"]:not(:checked) ~ ul#noteslist li[data-category=\"techbro\"],\n[value=\"revue\"]:not(:checked) ~ ul#noteslist li[data-category=\"revue\"],\n[value=\"tumblr\"]:not(:checked) ~ ul#noteslist li[data-category=\"tumblr\"],\n[value=\"writing\"]:not(:checked) ~ ul#noteslist li[data-category=\"writing\"]\n{\ndisplay: none;\n}\n\nul#noteslist li:first-of-type a:before {\ncontent: \"\";\n}\n\nmain label:after {\ncontent: \"\A\";\nwhite-space: pre;\n}\n</style>\n</head>\n<body>\n<nav>\n<input type=\"checkbox\" id=\"toggle\" name=\"toggle\">\n<label class=\"toggle-btn\" for=\"toggle\">Menu</label>\n<ul>\n<li>Fundamentals\n<ul>\n<li><a href=\"/\">Home</a></li>\n<li><a href=\"/about\">About + listings</a></li>\n<li><a href=\"/follow\">Follow</a></li>\n<li><a href=\"/feed.xml\">Changelog</a> <a href=\"/feed.xml\"><span class=\"rss\"></span></a></li>\n<li><a href=\"/sitemap.xml\">Sitemap</a></li>\n<li><a href=\"/siteroll\">Siteroll</a></li>\n</ul>\n</li>\n<li>Projects\n<ul>\n<li><a href=\"/fic\">Fanfiction</a> <a href=\"/fic/feed.xml\"><span class=\"rss\"></span></a></li>\n<li><a href=\"/music\">Music</a></li>\n<li>Journal</li>\n<li><a href=\"/trackers\">Trackers</a></li>\n<li><a href=\"https://git.praze.net/tre\" target=\"_blank\">Code</a> <a href=\"https://git.praze.net/tre.rss\"><span class=\"rss\"></span></a></li>\n<li><a href=\"https://img.praze.net\" target=\"_blank\">Photos</a> <a href=\"https://img.praze.net/feed.php\"><span class=\"rss\"></span></a></li>\n</ul>\n</li>\n<li>Fan content\n<ul>\n<li><a href=\"/ffx\">FFX</a></li>\n<li><a href=\"/xvi\">FF16</a></li>\n<li><a href=\"https://morgan.praze.net\" target=\"_blank\">Dermot Morgan</a> <a href=\"https://morgan.praze.net/feed.xml\"><span class=\"rss\"></span></a></li>\n</ul>\n</li>\n<li>Misc.\n<ul>\n<li><a href=\"https://tcg.praze.net\" target=\"_blank\">TCG</a></li>\n<li><a href=\"https://links.praze.net\" target=\"_blank\">Bookmarks</a> <a href=\"https://links.praze.net/feed/rss\"><span class=\"rss\"></span></a></li>\n<li><a href=\"https://kes.praze.net/@tre\" target=\"_blank\">Fediverse</a> <a href=\"https://kes.praze.net/@tre/feed.rss\"><span class=\"rss\"></span></a></li>\n</ul>\n</li>\n</ul>\n</nav>\n<div>\n<main>\n<section>\n<h1>Notes</h1>\n<p>This is the part of the site where I post long-ish-form writing I seem to have the embarrassing need to share&nbsp;… I guess you’d call it a blog.</p>\n<p>Posts are listed in reverse chronological order. Please be aware of posting dates&nbsp;– my opinions are constantly changing and evolving, and the longer ago something was written, the more likely it is that I’ll have since come to disagree with it completely&nbsp;… or in the case of more technical stuff, details may simply be out of date.</p>\n<p>Some of these posts were originally made on a now-deleted Dreamwidth account. Toggle the boxes to show/hide posts in the relevant category.</p>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"meme\" value=\"meme\" checked>\n<label for=\"meme\">Journal memes</label>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"month\" value=\"month\" checked>\n<label for=\"month\">Monthly roundup</label>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"techbro\" value=\"techbro\" checked>\n<label for=\"techbro\">Reminding myself how to do stuff</label>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"revue\" value=\"revue\" checked>\n<label for=\"revue\">Revues</label>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"tumblr\" value=\"tumblr\" checked>\n<label for=\"tumblr\">Tumblr tag games</label>\n<input name=\"filter\" class=\"input\" type=\"checkbox\" id=\"writing\" value=\"writing\" checked>\n<label for=\"writing\">Writing notes</label>\n<ul id=\"noteslist\">\n")
for post in posts:
poststring = "<li data-category=\"" + post["category"] + "\"><code>" + post["date"] + "</code> <a href=\"/notes/" + post["date"].replace("-","") + "\">"
try:
if post["media"] == "book":
poststring += "📚 "
elif post["media"] == "game":
poststring += "🎮 "
elif post["media"] == "music":
poststring += "🎵 "
elif post["media"] == "sight":
poststring += "🔭 "
elif post["media"] == "event":
poststring += "📅 "
except:
pass
poststring += post["real"] + "</a></li>\n"
writeindex.write(poststring)
writeindex.write("</ul>\n</section>\n</main>\n<footer>\n<ul>\n<li><a href=\"/\">home</a></li>\n</ul>\n</footer>\n</div>\n<a href=\"/\"><img src=\"/a.png\" style=\"position:fixed;bottom:2px;right:2px;\" title=\"home\"></a>\n</body>\n</html>\n")
writeindex.close()