mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-20 01:19:26 +01:00
RSS: Add support for feed attributes in template string
See https://feedparser.readthedocs.io/en/latest/common-rss-elements.html#accessing-common-channel-elements
This commit is contained in:
parent
8168c52939
commit
bb3d456fdf
@ -68,7 +68,9 @@ conf.registerChannelValue(RSS, 'format',
|
||||
will use for displaying headlines of a RSS feed that is triggered
|
||||
manually. In addition to fields defined by feedparser ($published
|
||||
(the entry date), $title, $link, $description, $id, etc.), the following
|
||||
variables can be used: $feed_name, $date (parsed date, as defined in
|
||||
variables can be used: $feed_name (the configured name)
|
||||
$feed_title/$feed_subtitle/$feed_author/$feed_language/$feed_link,
|
||||
$date (parsed date, as defined in
|
||||
supybot.reply.format.time)""")))
|
||||
conf.registerChannelValue(RSS, 'announceFormat',
|
||||
registry.String(_('News from $feed_name: $title <$link>'),
|
||||
|
@ -493,10 +493,11 @@ class RSS(callbacks.Plugin):
|
||||
template = self.registryValue(key_name, channel, network)
|
||||
date = entry.get('published_parsed')
|
||||
date = utils.str.timestamp(date)
|
||||
s = string.Template(template).safe_substitute(
|
||||
entry,
|
||||
feed_name=feed.name,
|
||||
date=date)
|
||||
kwargs = {"feed_%s" % k: v for (k, v) in feed.data.items() if
|
||||
isinstance(v, str)}
|
||||
kwargs["feed_name"] = feed.name
|
||||
kwargs.update(entry)
|
||||
s = string.Template(template).safe_substitute(entry, **kwargs, date=date)
|
||||
return self._normalize_entry(s)
|
||||
|
||||
def announce_entry(self, irc, channel, feed, entry):
|
||||
|
@ -359,6 +359,14 @@ class RSSTestCase(ChannelPluginTestCase):
|
||||
self.assertRegexp('rss http://xkcd.com/rss.xml',
|
||||
'On the other hand, the refractor\'s')
|
||||
|
||||
@mock_urllib
|
||||
def testFeedAttribute(self, mock):
|
||||
timeFastForward(1.1)
|
||||
with conf.supybot.plugins.RSS.format.context('$feed_title: $title'):
|
||||
mock._data = xkcd_new
|
||||
self.assertRegexp('rss http://xkcd.com/rss.xml',
|
||||
r'xkcd\.com: Telescopes')
|
||||
|
||||
@mock_urllib
|
||||
def testBadlyFormedFeedWithNoItems(self, mock):
|
||||
# This combination will cause the RSS command to show the last parser
|
||||
|
Loading…
Reference in New Issue
Block a user