From 708d7b3eee9769ec679b5a7fbcc688dda96c9dea Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 14 May 2013 07:37:33 -0400 Subject: [PATCH] command: Use feed names in OPML 'text' attributes Instead of writing the URL as the 'text' attribute and ignoring it on read, we now use the attribute to store the feed name. This avoids auto-generated feed names on import. From the OPML 2.0 spec [1]: Subscription lists ... Required attributes: type, text, xmlUrl. For outline elements whose type is rss, the text attribute should initially be the top-level title element in the feed being pointed to, however since it is user-editable, processors should not depend on it always containing the title of the feed. xmlUrl is the http address of the feed. We are not following the 'should' recommendation, but since we have user-generated titles, I believe that the new usage is appropriate. It's certainly closer to spec than storing a URL in 'text' :p. [1]: http://dev.opml.org/spec2.html Signed-off-by: W. Trevor King --- CHANGELOG | 1 + rss2email/command.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d7e6c31..6c9bb3a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ v3.5 (unreleased) * Fix html2text configuration (ignored since 2012-10-04). * Fix opmlexport crash due to orphaned feed data. + * Use feed names in OPML 'text' attributes. v3.4 (2013-05-14) * Added post-processing hooks for user-specified message manipulation. diff --git a/rss2email/command.py b/rss2email/command.py index c43e4ad..36dfca9 100644 --- a/rss2email/command.py +++ b/rss2email/command.py @@ -134,7 +134,12 @@ def opmlimport(feeds, args): for feed in new_feeds: if feed.hasAttribute('xmlUrl'): url = _saxutils.unescape(feed.getAttribute('xmlUrl')) - feed = feeds.new_feed(url=url) + name = None + if feed.hasAttribute('text'): + text = _saxutils.unescape(feed.getAttribute('text')) + if text != url: + name = text + feed = feeds.new_feed(name=name, url=url) _LOG.info('add new feed {}'.format(feed)) feeds.save() @@ -157,8 +162,10 @@ def opmlexport(feeds, args): if not feed.url: _LOG.debug('dropping {}'.format(feed)) continue + name = _saxutils.escape(feed.name) url = _saxutils.escape(feed.url) - f.write(''.format(url)) + f.write(''.format( + name, url)) f.write( '\n' '\n') -- 2.26.2