From: W. Trevor King Date: Sun, 30 Jun 2013 15:15:10 +0000 (-0400) Subject: aggregator: Add processors field for post-fetch processing hooks X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=65a6344351d2c82256f6407fa4b7529cbca53e4b;p=pycalendar.git aggregator: Add processors field for post-fetch processing hooks --- 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')