+ def atomForLD (ld):
+ doc = getDOMImplementation().createDocument(None, "feed", None)
+ atomElt = doc.documentElement
+ atomElt.setAttribute("xmlns", ATOM_NAMESPACE)
+ atomElt.setAttribute("xml:lang", LANG)
+ subject = ld["subject"] if "subject" in ld else "Statuses"
+ titleElt = atomElt.appendChild(doc.createElement("title"))
+ titleElt.appendChild(doc.createTextNode(f"{subject} @ {PUBLIC_URL}"))
+ updatedElt = atomElt.appendChild(doc.createElement("updated"))
+ updatedElt.appendChild(doc.createTextNode(CURRENT_DATETIME))
+ generatorElt = atomElt.appendChild(doc.createElement("generator"))
+ generatorElt.appendChild(doc.createTextNode("x_status_git"))
+ generatorElt.setAttribute("uri", "https://git.ladys.computer/x_status_git")
+ atomLinks = {}
+ if "OrderedCollectionPage" in ld["@type"]:
+ idElt = atomElt.appendChild(doc.createElement("id"))
+ idElt.appendChild(doc.createTextNode(f"{PUBLIC_URL}/statuses"))
+ atomLinks["alternate"] = f"{PUBLIC_URL}/statuses"
+ atomLinks["current"] = f"{PUBLIC_URL}/statuses.atom"
+ atomLinks["self"] = atomLinks["current"] if ld["@id"] == ld["current"] else f"{ld['@id']}.atom"
+ if "prev" in ld:
+ atomLinks["prev-archive"] = f"{ld['prev']}.atom"
+ if "next" in ld and ld["next"] != ld["current"]:
+ atomLinks["next-archive"] = f"{ld['next']}.atom"
+ else:
+ idElt = atomElt.appendChild(doc.createElement("id"))
+ idElt.appendChild(doc.createTextNode(ld["@id"]))
+ atomLinks["alternate"] = ld["@id"]
+ atomLinks["self"] = f"{ld['@id']}.atom"
+ for (rel, href) in atomLinks.items():
+ linkElt = atomElt.appendChild(doc.createElement("link"))
+ linkElt.setAttribute("rel", rel)
+ linkElt.setAttribute("href", href)
+ for item in ld["items"]:
+ entryElt = atomElt.appendChild(doc.createElement("entry"))
+ title = item["source"]["content"].partition("\n")[0]
+ if "title" in item:
+ title = item["title"]
+ elif len(title) >= 28:
+ title = title[0:27] + "…"
+ titleElt = entryElt.appendChild(doc.createElement("title"))
+ titleElt.appendChild(doc.createTextNode(title))
+ idElt = entryElt.appendChild(doc.createElement("id"))
+ idElt.appendChild(doc.createTextNode(item["@id"]))
+ updatedElt = entryElt.appendChild(doc.createElement("updated"))
+ updatedElt.appendChild(doc.createTextNode(CURRENT_DATETIME))
+ if "created" in item:
+ publishedElt = entryElt.appendChild(doc.createElement("published"))
+ publishedElt.appendChild(doc.createTextNode(item["created"]))
+ authorElt = entryElt.appendChild(doc.createElement("author"))
+ if "author" in item:
+ nameElt = authorElt.appendChild(doc.createElement("name"))
+ nameElt.appendChild(doc.createTextNode(item["author"]["name"]))
+ uriElt = authorElt.appendChild(doc.createElement("uri"))
+ uriElt.appendChild(doc.createTextNode(item["author"]["@id"]))
+ else:
+ nameElt = authorElt.appendChild(doc.createElement("name"))
+ nameElt.appendChild(doc.createTextNode("Anonymous"))
+ contentElt = entryElt.appendChild(doc.createElement("content"))
+ contentElt.setAttribute("type", "xhtml")
+ contentDiv = contentElt.appendChild(doc.createElement("div"))
+ contentDiv.setAttribute("xmlns", XHTML_NAMESPACE)
+ contentDiv.setAttribute("lang", LANG)
+ for child in list(parseString(item["content"]).documentElement.childNodes):
+ contentDiv.appendChild(child)
+ return (atomLinks["self"], atomElt.toxml())
+