feeds: pass parent Feed to Items

master
pictuga 2020-03-17 12:22:14 +01:00
parent 9c557ea02c
commit fe46c6c522
1 changed files with 5 additions and 3 deletions

View File

@ -60,7 +60,7 @@ def parse_rules(filename=None):
class ParserBase(object): class ParserBase(object):
def __init__(self, data=None, rules=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()['rss']
@ -69,6 +69,7 @@ class ParserBase(object):
self.rules = rules self.rules = rules
self.root = self.parse(data) self.root = self.parse(data)
self.parent = parent
# do `if multi` and select the correct rule for each (and split \n) # do `if multi` and select the correct rule for each (and split \n)
if isinstance(self.rules['items'], list): if isinstance(self.rules['items'], list):
@ -409,7 +410,7 @@ class Feed(object):
def wrap_items(self, items): def wrap_items(self, items):
itemsClass = globals()[self.itemsClass] itemsClass = globals()[self.itemsClass]
return [itemsClass(x, self.rules) for x in items] return [itemsClass(x, self.rules, self) for x in items]
title = property( title = property(
lambda f: f.get_str('title'), lambda f: f.get_str('title'),
@ -449,10 +450,11 @@ class Feed(object):
class Item(Uniq): class Item(Uniq):
dic = ('title', 'link', 'desc', 'content', 'id', 'is_permalink', 'time', 'updated') dic = ('title', 'link', 'desc', 'content', 'id', 'is_permalink', 'time', 'updated')
def __init__(self, xml=None, rules=None): def __init__(self, xml=None, rules=None, parent=None):
self._id = self._gen_id(xml) self._id = self._gen_id(xml)
self.root = xml self.root = xml
self.rules = rules self.rules = rules
self.parent = parent
@staticmethod @staticmethod
def _gen_id(xml=None, *args, **kwargs): def _gen_id(xml=None, *args, **kwargs):