From d42e19a165c17a607f1f7a0d7e6c0ee3345b8daf Mon Sep 17 00:00:00 2001 From: pictuga Date: Tue, 17 Mar 2020 12:23:36 +0100 Subject: [PATCH] feeds: beter rules handling "Dynamic" rule set picking, better handling of non-multi rules --- morss/feeds.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/morss/feeds.py b/morss/feeds.py index 9d3fe65..c6f53cf 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -62,12 +62,17 @@ def parse_rules(filename=None): class ParserBase(object): def __init__(self, data=None, rules=None, parent=None): if rules is None: - rules = parse_rules()['rss'] - - if data is None: - data = rules['base'][0] + rules = parse_rules()[self.ruleset] # FIXME 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.parent = parent @@ -230,6 +235,8 @@ class ParserBase(object): class ParserXML(ParserBase): + ruleset = 'rss' + NSMAP = {'atom': 'http://www.w3.org/2005/Atom', 'atom03': 'http://purl.org/atom/ns#', 'media': 'http://search.yahoo.com/mrss/',