Add basic RSS feed functionality

master
trémeur 9 months ago
parent 343a7edc9c
commit 8ce59823a2

@ -12,6 +12,7 @@ Rename =variables-template.py= to =variables.py= and edit:
- =orgpath=: absolute path to the root directory in which =.org= files are stored, including trailing slash - =orgpath=: absolute path to the root directory in which =.org= files are stored, including trailing slash
- =localpath=: absolute path to this directory, including trailing slash - =localpath=: absolute path to this directory, including trailing slash
- =serverpath=: path to directory on the server where files will be uploaded, including trailing slash - =serverpath=: path to directory on the server where files will be uploaded, including trailing slash
- =domain=: =https://yourdomain.tld= without trailing slash
- =rclonesiteroot=: path =rclone= uses to access your webserver - =rclonesiteroot=: path =rclone= uses to access your webserver
- =description=: content for the “about” section (can include HTML tags) - =description=: content for the “about” section (can include HTML tags)
- =hue=: theme colour expressed as a hue from 0 to 360 - =hue=: theme colour expressed as a hue from 0 to 360

@ -3,15 +3,17 @@ import gamesort,skeleton,variables
from datetime import datetime,timedelta from datetime import datetime,timedelta
""" """
Generates history page Generates history page and RSS feed
""" """
def history(local=False): def history(local=False):
# delete existing file # delete existing files
if not os.path.isdir("build/history"): if not os.path.isdir("build/history"):
os.mkdir("build/history") os.mkdir("build/history")
if os.path.exists("build/history/index.html"): if os.path.exists("build/history/index.html"):
os.remove("build/history/index.html") os.remove("build/history/index.html")
if os.path.exists("build/feed.xml"):
os.remove("build/feed.xml")
# write header # write header
skeleton.headerwrite("build/history/index.html","history",local) skeleton.headerwrite("build/history/index.html","history",local)
output = "build/history/index.html" output = "build/history/index.html"
@ -19,6 +21,9 @@ def history(local=False):
filewrite.write(" <section class=\"history\">\n <div class=\"list\">\n") filewrite.write(" <section class=\"history\">\n <div class=\"list\">\n")
feedwrite = open("build/feed.xml", "a")
feedwrite.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n <channel>\n <atom:link href=\"" + variables.domain + variables.serverpath + "feed.xml\" rel=\"self\" type=\"application/rss+xml\" />\n <title>Static backlog</title>\n <link>" + variables.domain + variables.serverpath + "backlog</link>\n <description>Feed for gaming updates</description>\n <language>en-gb</language>")
theyear = int(gamesort.thisyear) theyear = int(gamesort.thisyear)
while theyear > 2016: while theyear > 2016:
yearlist = [] yearlist = []
@ -60,9 +65,13 @@ def history(local=False):
else: else:
filewrite.write(event["action"]) filewrite.write(event["action"])
filewrite.write("\"></div>\n </div>\n <div> " + event["name"] + "\n <span>(" + event["console"] + ")</span>\n </div>\n </div>\n </div>\n") filewrite.write("\"></div>\n </div>\n <div> " + event["name"] + "\n <span>(" + event["console"] + ")</span>\n </div>\n </div>\n </div>\n")
feedwrite.write(" <item>\n <title>" + event["action"] + " " + event["name"] + " (" + event["console"] + ")</title>\n <pubDate>" + event["date"].strftime("%a, %-d %b %Y") + " 00:00:00 UT</pubDate>\n <link>" + variables.domain + variables.serverpath + "history</link>\n <guid isPermaLink=\"false\">" + event["action"] + "-" + event["name"].replace(" ","-") + "-" + event["console"] + "</guid>\n <description>" + event["action"] + " " + event["name"] + " (" + event["console"] + ")</description>\n </item>\n")
checkdate = event["date"] checkdate = event["date"]
theyear -= 1 theyear -= 1
feedwrite.write(" </channel>\n</rss>")
feedwrite.close()
filewrite.write(" </div>\n") filewrite.write(" </div>\n")
theyear = int(gamesort.thisyear) theyear = int(gamesort.thisyear)

@ -14,7 +14,7 @@ def headerwrite(output,section,local=False):
hexstring = "" hexstring = ""
for element in rgb: for element in rgb:
hexstring += str(hex(int(element * 255)))[2:] hexstring += str(hex(int(element * 255)))[2:]
header.write("<!DOCTYPE html>\n<html lang=\"en\" style=\"--active-base: hsl(" + str(variables.hue) + ", 45%, 30%); --active-secondary: hsl(" + str(variables.hue) + ", 15%, 30%); --active-accent: hsl(" + str(variables.hue) + ", 90%, 70%);\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <meta name=\"theme-color\" content=\"#" + hexstring + "\">\n <link href=\"https://fonts.googleapis.com/icon?family=Material+Icons\" rel=\"stylesheet\">\n <link href=\"https://fonts.googleapis.com/css?family=Lato|Teko|Titillium+Web\" rel=\"stylesheet\">\n <title>Static backlog</title>\n <link href=\"") header.write("<!DOCTYPE html>\n<html lang=\"en\" style=\"--active-base: hsl(" + str(variables.hue) + ", 45%, 30%); --active-secondary: hsl(" + str(variables.hue) + ", 15%, 30%); --active-accent: hsl(" + str(variables.hue) + ", 90%, 70%);\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <meta name=\"theme-color\" content=\"#" + hexstring + "\">\n <link href=\"https://fonts.googleapis.com/icon?family=Material+Icons\" rel=\"stylesheet\">\n <link href=\"https://fonts.googleapis.com/css?family=Lato|Teko|Titillium+Web\" rel=\"stylesheet\">\n <title>Static backlog</title>\n <link rel=\"alternate\" type=\"application/rss+xml\" title=\"Static backlog\" href=\"" + variables.serverpath + "feed.xml\">\n <link href=\"")
if local: if local:
header.write(variables.localpath + "build/") header.write(variables.localpath + "build/")
else: else:

@ -10,6 +10,8 @@ localpath = ""
serverpath = "" serverpath = ""
domain = ""
rcloneaddress = "" rcloneaddress = ""
description = "" description = ""

Loading…
Cancel
Save