feeds: beter rules handling

"Dynamic" rule set picking, better handling of non-multi rules
master
pictuga 2020-03-17 12:23:36 +01:00
parent fe46c6c522
commit d42e19a165
1 changed files with 11 additions and 4 deletions

View File

@ -62,12 +62,17 @@ def parse_rules(filename=None):
class ParserBase(object): class ParserBase(object):
def __init__(self, data=None, rules=None, parent=None): def __init__(self, data=None, rules=None, parent=None):
if rules is None: if rules is None:
rules = parse_rules()['rss'] rules = parse_rules()[self.ruleset] # FIXME
if data is None:
data = rules['base'][0]
self.rules = rules self.rules = rules
if data is None:
if isinstance(self.rules['items'], list):
data = rules['base'][0]
else:
data = rules['base']
self.root = self.parse(data) self.root = self.parse(data)
self.parent = parent self.parent = parent
@ -230,6 +235,8 @@ class ParserBase(object):
class ParserXML(ParserBase): class ParserXML(ParserBase):
ruleset = 'rss'
NSMAP = {'atom': 'http://www.w3.org/2005/Atom', NSMAP = {'atom': 'http://www.w3.org/2005/Atom',
'atom03': 'http://purl.org/atom/ns#', 'atom03': 'http://purl.org/atom/ns#',
'media': 'http://search.yahoo.com/mrss/', 'media': 'http://search.yahoo.com/mrss/',