AX_PYTHON_MODULE([fastapi], [fatal])
AX_PYTHON_MODULE([httpx], [fatal])
AX_PYTHON_MODULE([ldap], [fatal])
+AX_PYTHON_MODULE([lxml], [fatal])
AX_PYTHON_MODULE([publicsuffix2], [fatal])
AX_PYTHON_MODULE([rich], [fatal])
AX_PYTHON_MODULE([sqlmodel], [fatal])
# #
###############################################################################
+import datetime
import fastapi
+import lxml.etree
import pydantic
import typing
import uuid
# Create the comment
return await report.comment(comment=comment.comment, reporter=user)
+
+"""
+ RSS
+"""
+@router.get(".rss")
+async def rss(
+ open: bool | None = None,
+ limit: int = 100,
+):
+ # Fetch the current time
+ now = datetime.datetime.utcnow()
+
+ # Atom Feed namespace
+ ATOM_NS = "http://www.w3.org/2005/Atom"
+
+ # Create a new XML object
+ root = lxml.etree.Element("rss", version="2.0", nsmap={ "atom" : ATOM_NS })
+
+ # Meta information
+ channel = lxml.etree.SubElement(root, "channel")
+ lxml.etree.SubElement(channel, "title").text = "IPFire DBL - Reports Feed"
+ lxml.etree.SubElement(channel, "link").text = "https://www.ipfire.org/dbl"
+ lxml.etree.SubElement(channel, "description").text = "Latest Reports"
+ lxml.etree.SubElement(channel, "lastBuildDate").text = now.strftime("%a, %d %b %Y %H:%M:%S +0000")
+
+ # Atom link to itself
+ atom_link = lxml.etree.SubElement(channel, "{%s}link" % ATOM_NS)
+ atom_link.set("href", "https://api.dbl.ipfire.org/reports.rss")
+ atom_link.set("rel", "self")
+ atom_link.set("type", "application/rss+xml")
+
+ # Fetch the latest reports
+ async for report in backend.reports.get(open=open, limit=limit):
+ # Create a new item
+ item = lxml.etree.SubElement(channel, "item")
+
+ # Title
+ lxml.etree.SubElement(item, "title").text = report.title
+
+ # Set the URL has target link and GUID
+ lxml.etree.SubElement(item, "link").text = report.url
+ lxml.etree.SubElement(item, "guid").text = report.url
+
+ # Set the date
+ lxml.etree.SubElement(item, "pubDate").text = \
+ report.reported_at.strftime("%a, %d %b %Y %H:%M:%S +0000")
+
+ # Serialize the XML document
+ content = lxml.etree.tostring(root,
+ pretty_print=True, xml_declaration=True, encoding="UTF-8")
+
+ # Send it to the client
+ return fastapi.Response(content=content, media_type="application/rss+xml")
+
+
# Include our endpoints
app.include_router(router)