From: W. Trevor King Date: Fri, 10 May 2013 09:36:25 +0000 (-0400) Subject: feed: Add the digest-post-process setting X-Git-Tag: v3.5~2^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c84b6880d0777756494f81e029093f0b0aeb658b;p=rss2email.git feed: Add the digest-post-process setting For users that want to manipulate the multi-entry message. For example, if the stock `digest for ` title doesn't cut it for you, you can now use a post-processing hook to set the title however you like. Signed-off-by: W. Trevor King --- diff --git a/rss2email/config.py b/rss2email/config.py index 1a2faa0..94bab6b 100644 --- a/rss2email/config.py +++ b/rss2email/config.py @@ -105,6 +105,12 @@ CONFIG['DEFAULT'] = _collections.OrderedDict(( # User processing hooks. Note the space after the module name. # Example: post-process = 'rss2email.post_process.downcase downcase_message' ('post-process', ''), + # User processing hooks for digest messages. If 'digest' is + # enabled, the usual 'post-process' hook gets to massage the + # per-entry messages, but this hook is called with the full + # digest message before it is mailed. + # Example: digest-post-process = 'rss2email.post_process.downcase downcase_message' + ('digest-post-process', ''), ## HTML conversion # True: Send text/html messages when possible. # False: Convert HTML to plain text. diff --git a/rss2email/feed.py b/rss2email/feed.py index b2497d7..544189b 100644 --- a/rss2email/feed.py +++ b/rss2email/feed.py @@ -188,6 +188,7 @@ class Feed (object): _function_attributes = [ 'post_process', + 'digest_post_process', ] def __init__(self, name=None, url=None, to=None, config=None): @@ -810,6 +811,11 @@ class Feed (object): self.seen[guid]['id'] = id_ if self.digest and seen: + if self.digest_post_process: + digest = self.digest_post_process( + feed=self, parsed=parsed, seen=seen, message=digest) + if not digest: + return self._send_digest( digest=digest, seen=seen, sender=sender, send=send) diff --git a/rss2email/post_process/__init__.py b/rss2email/post_process/__init__.py index e9dd2b9..02b6da0 100644 --- a/rss2email/post_process/__init__.py +++ b/rss2email/post_process/__init__.py @@ -34,4 +34,11 @@ message: Post-processing hooks should return the possibly altered message, or return ``None`` to indicate that the message should not be sent. + +For feeds with the ``digest`` setting enabled, there is a similar +``digest-post-process`` hook, which, when set, is called by +``Feed.run()``. The keyword arguments are mostly the same as for the +standard post-processing hook, however ``entry`` and ``guid`` are +replaced by ``seen``, a list of ``(guid, id_)`` tuples for each entry +part contained in the digest message. """ diff --git a/test/gmane/2.config b/test/gmane/2.config index e4abd7a..4d2aa1f 100644 --- a/test/gmane/2.config +++ b/test/gmane/2.config @@ -2,3 +2,4 @@ to = a@b.com date-header = True digest = True +digest-post-process = rss2email.post_process.downcase downcase_message diff --git a/test/gmane/2.expected b/test/gmane/2.expected index 28ed04f..555b7f8 100644 --- a/test/gmane/2.expected +++ b/test/gmane/2.expected @@ -4,7 +4,7 @@ MIME-Version: 1.0 To: a@b.com Subject: digest for test Message-ID: <...@dev.null.invalid> -User-Agent: rss2email/3.2 +https://github.com/wking/rss2email +User-Agent: rss2email/3.3 +https://github.com/wking/rss2email X-RSS-Feed: gmane/feed.rss From: "gmane.mail.rss2email: W. Trevor King" Date: Tue, 13 Nov 2012 14:36:22 -0000 @@ -22,46 +22,46 @@ To: a@b.com Subject: Re: new maintainer and mailing list for rss2email Date: Mon, 12 Nov 2012 21:20:22 -0000 Message-ID: <...@dev.null.invalid> -User-Agent: rss2email/3.2 +https://github.com/wking/rss2email +User-Agent: rss2email/3.3 +https://github.com/wking/rss2email X-RSS-Feed: gmane/feed.rss X-RSS-ID: http://permalink.gmane.org/gmane.mail.rss2email/1 X-RSS-URL: http://permalink.gmane.org/gmane.mail.rss2email/1 -Alrighty, this is the first email on the list and also my first +alrighty, this is the first email on the list and also my first - production mlmmj list, so I've CCed you both directly. Etienne, let + production mlmmj list, so i've cced you both directly. etienne, let me know if you get the direct email but not the list email, in which - case I'll try and figure out what I've miss-configured ;). Lindsey, - I'll direct future rss2email stuff to my new list, so subscribe if + case i'll try and figure out what i've miss-configured ;). lindsey, + i'll direct future rss2email stuff to my new list, so subscribe if you're interested. - On Mon, Nov 12, 2012 at 06:17:50PM +0100, Etienne Millon wrote: + on mon, nov 12, 2012 at 06:17:50pm +0100, etienne millon wrote: - Wonderful. Let me know if you come up with anything during a - test-drive, and I'll get it in before the 3.0 release. + wonderful. let me know if you come up with anything during a + test-drive, and i'll get it in before the 3.0 release. - The 2.x config format is pure Python, which means the users can do + the 2.x config format is pure python, which means the users can do whatever they want there (including monkey-patching urllib2, changing - the rss2email version number, etc.). It's hard to imagine a robust + the rss2email version number, etc.). it's hard to imagine a robust way to migrate everything a user may have done in there. - If you want to take a stab at it, I'll be happy to add it to a contrib + if you want to take a stab at it, i'll be happy to add it to a contrib directory :). - Great :). + great :). - On Mon, Nov 12, 2012 at 01:48:13PM -0500, W. Trevor King wrote: + on mon, nov 12, 2012 at 01:48:13pm -0500, w. trevor king wrote: - Done: https://github.com/wking/rss2email + done: https://github.com/wking/rss2email -URL: http://permalink.gmane.org/gmane.mail.rss2email/1 +url: http://permalink.gmane.org/gmane.mail.rss2email/1 --===============...== Content-Type: message/rfc822 MIME-Version: 1.0 @@ -75,35 +75,35 @@ To: a@b.com Subject: Re: new maintainer and mailing list for rss2email Date: Tue, 13 Nov 2012 10:48:07 -0000 Message-ID: <...@dev.null.invalid> -User-Agent: rss2email/3.2 +https://github.com/wking/rss2email +User-Agent: rss2email/3.3 +https://github.com/wking/rss2email X-RSS-Feed: gmane/feed.rss X-RSS-ID: http://permalink.gmane.org/gmane.mail.rss2email/2 X-RSS-URL: http://permalink.gmane.org/gmane.mail.rss2email/2 -* W. Trevor King public.gmane.org> [121112 23:18]: +* w. trevor king public.gmane.org> [121112 23:18]: - It seems to work, though it may have been grouped together with my - MDA. I'll tell you if I don't receive a mail where I'm not CCed. + it seems to work, though it may have been grouped together with my + mda. i'll tell you if i don't receive a mail where i'm not cced. - We're finalizing a release ATM, so it will be the perfect time to try + we're finalizing a release atm, so it will be the perfect time to try a new rss2email release in a couple of months. - The idea is more to migrate the low hanging fruits (maybe 95% of - users) so that they don't lose their config. I was thinking to just + the idea is more to migrate the low hanging fruits (maybe 95% of + users) so that they don't lose their config. i was thinking to just eval() the config file and output the relevant variables to the new - format. We'll see how it turns out :) + format. we'll see how it turns out :) - Do you prefer taking pull requests there or as a discussion on the + do you prefer taking pull requests there or as a discussion on the mailing list (git send-email style) ? -URL: http://permalink.gmane.org/gmane.mail.rss2email/2 +url: http://permalink.gmane.org/gmane.mail.rss2email/2 --===============...== Content-Type: message/rfc822 MIME-Version: 1.0 @@ -117,19 +117,19 @@ To: a@b.com Subject: Re: new maintainer and mailing list for rss2email Date: Tue, 13 Nov 2012 12:20:20 -0000 Message-ID: <...@dev.null.invalid> -User-Agent: rss2email/3.2 +https://github.com/wking/rss2email +User-Agent: rss2email/3.3 +https://github.com/wking/rss2email X-RSS-Feed: gmane/feed.rss X-RSS-ID: http://permalink.gmane.org/gmane.mail.rss2email/3 X-RSS-URL: http://permalink.gmane.org/gmane.mail.rss2email/3 - send-email style, although I'll accept anything ;). + send-email style, although i'll accept anything ;). -URL: http://permalink.gmane.org/gmane.mail.rss2email/3 +url: http://permalink.gmane.org/gmane.mail.rss2email/3 --===============...== Content-Type: message/rfc822 MIME-Version: 1.0 @@ -143,22 +143,22 @@ To: a@b.com Subject: Re: new maintainer and mailing list for rss2email Date: Tue, 13 Nov 2012 12:42:13 -0000 Message-ID: <...@dev.null.invalid> -User-Agent: rss2email/3.2 +https://github.com/wking/rss2email +User-Agent: rss2email/3.3 +https://github.com/wking/rss2email X-RSS-Feed: gmane/feed.rss X-RSS-ID: http://permalink.gmane.org/gmane.mail.rss2email/4 X-RSS-URL: http://permalink.gmane.org/gmane.mail.rss2email/4 -* W. Trevor King public.gmane.org> [121113 13:21]: +* w. trevor king public.gmane.org> [121113 13:21]: - Ack. + ack. - Also, confirming that the mailing list works. + also, confirming that the mailing list works. -URL: http://permalink.gmane.org/gmane.mail.rss2email/4 +url: http://permalink.gmane.org/gmane.mail.rss2email/4 --===============...== Content-Type: message/rfc822 MIME-Version: 1.0 @@ -172,12 +172,12 @@ To: a@b.com Subject: split massive package into modules Date: Tue, 13 Nov 2012 14:36:22 -0000 Message-ID: <...@dev.null.invalid> -User-Agent: rss2email/3.2 +https://github.com/wking/rss2email +User-Agent: rss2email/3.3 +https://github.com/wking/rss2email X-RSS-Feed: gmane/feed.rss X-RSS-ID: http://permalink.gmane.org/gmane.mail.rss2email/5 X-RSS-URL: http://permalink.gmane.org/gmane.mail.rss2email/5 -I just split the 1769-line rss2email.py module into a more manageable +i just split the 1769-line rss2email.py module into a more manageable package with sub-modules: @@ -187,5 +187,5 @@ I just split the 1769-line rss2email.py module into a more manageable -URL: http://permalink.gmane.org/gmane.mail.rss2email/5 +url: http://permalink.gmane.org/gmane.mail.rss2email/5 --===============...==--