Generate RSS feed

This commit is contained in:
mez 2025-06-13 21:57:22 +01:00
parent 19824ab16f
commit 6ac889da24
5 changed files with 113 additions and 3 deletions

42
rssgen.py Normal file
View file

@ -0,0 +1,42 @@
import therss
import re
from bs4 import BeautifulSoup
writerss = open("feed.xml","w")
writerss.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"feed.xsl\" type=\"text/xsl\"?>\n<rss xmlns:atom=\"http://www.w3.org/2005/Atom\" version=\"2.0\">\n <channel>\n <atom:link href=\"https://tre.praze.net/feed.xml\" rel=\"self\" type=\"application/rss+xml\"/>\n <title>tre.praze.net</title>\n <link>https://tre.praze.net</link>\n <description>A feed for general updates at tre.praze.net</description>\n <language>en-gb</language>\n")
rssno = len(therss.rss)
for entry in therss.rss:
writerss.write(" <item>\n")
try:
if entry["real"]:
writerss.write(" <title>" + entry["real"] + "</title>\n")
except:
writerss.write(" <title>" + entry["title"] + "</title>\n")
writerss.write(" <pubDate>" + entry["rssdatetime"] + "</pubDate>\n <link>" + entry["url"] + "</link>\n <guid isPermaLink=\"false\">tre" + str(rssno) + "</guid>\n <description>")
if entry["desc"] == "placeholder":
htmlfile = open(entry["date"] + ".html","r")
soup = BeautifulSoup(htmlfile,features="lxml")
thepost = soup.find("div",class_="e-content")
try:
thetitle = soup.find("h1",class_="p-name")
writerss.write("<![CDATA[" + str(thetitle) + re.sub("href=\".\"",("href=\"" + entry["url"] + "\""),re.sub("src=\"/","src=\"https://tre.praze.net/",re.sub("href=\"/","href=\"https://tre.praze.net/",re.sub("\"/>","\">",re.sub("\n","",str(thepost)))))) + "]]>")
except:
writerss.write("<![CDATA[" + re.sub("href=\".\"",("href=\"" + entry["url"] + "\""),re.sub("src=\"/","src=\"https://tre.praze.net/",re.sub("href=\"/","href=\"https://tre.praze.net/",re.sub("\"/>","\">",re.sub("\n","",str(thepost)))))) + "]]>")
else:
writerss.write(entry["desc"])
writerss.write("</description>\n")
try:
for category in entry["categories"]:
writerss.write(" <category>" + category + "</category>\n")
except:
pass
writerss.write(" </item>\n")
rssno -= 1
writerss.write(" </channel>\n</rss>")
writerss.close()