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("\n\n
\n \n \npraze • Notes \n \n \n \n \n \n \n \n \n \n \n \n \n\n\n\n\n \nMenu \n\nFundamentals\n\n \nProjects\n\n \nFan content\n\n \nMisc.\n\n \n \n \n\n \n\n\n")
writeindex.close()