From 65a6344351d2c82256f6407fa4b7529cbca53e4b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 30 Jun 2013 11:15:10 -0400 Subject: [PATCH] aggregator: Add processors field for post-fetch processing hooks --- pycalendar/aggregator.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pycalendar/aggregator.py b/pycalendar/aggregator.py index c54b122..6b611b9 100644 --- a/pycalendar/aggregator.py +++ b/pycalendar/aggregator.py @@ -14,15 +14,22 @@ class Aggregator (list): >>> from .feed import Feed + You can set processing hooks to analyze and manipulate feeds as + they come in. + + >>> processors = [lambda feed: print("I'm processing {!r}".format(feed))] + >>> a = Aggregator( ... prodid='-//pycalendar//NONSGML testing//EN', ... feeds=[ ... Feed(url='{}/{}'.format(base_url, name)) ... for name in ['geohash.ics',]], + ... processors=processors, ... ) >>> a # doctest: +ELLIPSIS [] - >>> a.fetch() + >>> a.fetch() # doctest: +ELLIPSIS + I'm processing Generate aggregate calendars with the ``.write`` method. @@ -49,16 +56,21 @@ class Aggregator (list): END:VCALENDAR """ - def __init__(self, prodid, version='2.0', feeds=None): + def __init__(self, prodid, version='2.0', feeds=None, processors=None): super(Aggregator, self).__init__() self.prodid = prodid self.version = version if feeds: self.extend(feeds) + if not processors: + processors = [] + self.processors = processors def fetch(self): for feed in self: feed.fetch() + for processor in self.processors: + processor(feed) def write(self, stream): stream.write('BEGIN:VCALENDAR\r\n') -- 2.26.2