aboutsummaryrefslogtreecommitdiff
path: root/rss/rss_item.py
diff options
context:
space:
mode:
Diffstat (limited to 'rss/rss_item.py')
-rw-r--r--rss/rss_item.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/rss/rss_item.py b/rss/rss_item.py
new file mode 100644
index 00000000..8ead20e6
--- /dev/null
+++ b/rss/rss_item.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+
+import lxml.etree as ET
+
+class RssItem(object):
+ """Class for storing an RSS 2.0 item."""
+
+ ELEMENTS = ["title", "link", "description", "author", "category", "comments",
+ "enclosure", "guid", "pubDate", "source"]
+
+ def __init__(self):
+ """Define available attributes."""
+ for element in self.ELEMENTS:
+ setattr(self, element, None)
+ self.timestamp = None
+ self.item = None
+
+ def assemble_item(self):
+ """Assemble an RSS 2.0 item."""
+ self.item = ET.Element("item")
+ for element in self.ELEMENTS:
+ attr = getattr(self, element)
+ if attr is not None:
+ self.item.append(attr)
+
+ def dump_item(self):
+ """Dump RSS item XML."""
+ if self.item is None:
+ self.assemble_item()
+ return ET.tostring(self.item).decode("utf-8")