parent
d97a72bc0b
commit
0badec72a9
23
feeds.py
23
feeds.py
|
@ -76,6 +76,27 @@ class FeedBase(object):
|
||||||
Base for xml-related classes, which provides simple wrappers around xpath
|
Base for xml-related classes, which provides simple wrappers around xpath
|
||||||
selection and item creation
|
selection and item creation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __getitem__(self, item):
|
||||||
|
return getattr(self, item)
|
||||||
|
|
||||||
|
def __setitem__(self, item, value):
|
||||||
|
setattr(self, item, value)
|
||||||
|
|
||||||
|
def __delitem__(self, item):
|
||||||
|
delattr(self, item)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
for element in self.dic:
|
||||||
|
value = self[element]
|
||||||
|
|
||||||
|
if isinstance(value, FeedList):
|
||||||
|
value = [dict(x) for x in value]
|
||||||
|
elif isinstance(value, datetime):
|
||||||
|
value = value.isoformat()
|
||||||
|
|
||||||
|
yield element, value
|
||||||
|
|
||||||
def xpath(self, path):
|
def xpath(self, path):
|
||||||
""" Test xpath rule on xml tree """
|
""" Test xpath rule on xml tree """
|
||||||
return self.root.xpath(path, namespaces=NSMAP)
|
return self.root.xpath(path, namespaces=NSMAP)
|
||||||
|
@ -270,6 +291,7 @@ class FeedParser(FeedBase):
|
||||||
itemsClass = 'FeedItem'
|
itemsClass = 'FeedItem'
|
||||||
mimetype = 'application/xml'
|
mimetype = 'application/xml'
|
||||||
base = '<?xml?>'
|
base = '<?xml?>'
|
||||||
|
dic = ('title', 'desc', 'items')
|
||||||
|
|
||||||
def __init__(self, xml=None, tag='atom:feed'):
|
def __init__(self, xml=None, tag='atom:feed'):
|
||||||
if xml is None:
|
if xml is None:
|
||||||
|
@ -387,6 +409,7 @@ class FeedParserAtom(FeedParser):
|
||||||
|
|
||||||
class FeedItem(FeedBase):
|
class FeedItem(FeedBase):
|
||||||
timeFormat = ''
|
timeFormat = ''
|
||||||
|
dic = ('title', 'link', 'isPermaLink', 'desc', 'content', 'id', 'time', 'updated')
|
||||||
|
|
||||||
def __init__(self, xml=None, tag='atom:feed'):
|
def __init__(self, xml=None, tag='atom:feed'):
|
||||||
if xml is None:
|
if xml is None:
|
||||||
|
|
Loading…
Reference in New Issue