blob: 4b6e116a18d2a3168a25a7b00c76148b76355231 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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")
|