From 8e8d884d1c78641fbb967479bd4ddcb320da150e Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 30 Jul 2018 20:37:26 +0200 Subject: Move rss code to a package --- rss/atom_entry.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 rss/atom_entry.py (limited to 'rss/atom_entry.py') diff --git a/rss/atom_entry.py b/rss/atom_entry.py new file mode 100644 index 00000000..4b6e116a --- /dev/null +++ b/rss/atom_entry.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import lxml.etree as ET + +class AtomEntry(object): + """Class for storing atom:entry data and metadata.""" + + # pylint: disable=invalid-name,too-many-instance-attributes + + def __init__(self): + """Define available attributes.""" + self.author = None # atom:author + self.id_text = None # atom:id, just use URI + self.id = None # atom:id + self.relpath = None # HTML page path relative to home + self.link = None # atom:link + self.title_text = None # plain text title + self.title = None # atom:title + self.updated_datetime = None # update time as a datetime object + self.updated = None # atom:updated + self.content_html = None # content as HTML markup + self.content = None # atom:content + self.entry = None # atom:entry, assembled + + def assemble_entry(self): + """Assemble atom:entry.""" + self.entry = ET.Element("entry") + self.entry.append(self.title) + self.entry.append(self.link) + self.entry.append(self.updated) + self.entry.append(self.id) + self.entry.append(self.author) + self.entry.append(self.content) + + def dump_entry(self): + """Dump atom:entry XML.""" + if self.entry is None: + self.assemble_entry() + return ET.tostring(self.entry).decode("utf-8") -- cgit v1.2.1