RSS: Sort on time tuples instead of formatted dates.

This commit is contained in:
Valentin Lorentz 2015-09-02 09:43:29 +02:00
parent c81d5d3151
commit 29ca3eb5e4
2 changed files with 30 additions and 2 deletions

View File

@ -132,7 +132,7 @@ def sort_feed_items(items, order):
if order == 'newestFirst':
reverse = True
try:
sitems = sorted(items, key=lambda i: i['published'], reverse=reverse)
sitems = sorted(items, key=lambda i: i['published_parsed'], reverse=reverse)
except KeyError:
# feedparser normalizes required timestamp fields in ATOM and RSS
# to the "published" field. Feeds missing it are unsortable by date.

View File

@ -69,7 +69,35 @@ class RSSTestCase(ChannelPluginTestCase):
finally:
self.assertNotError('rss remove xkcd')
def testInitialAnnounce(self):
def testInitialAnnounceNewest(self):
old_open = feedparser._open_resource
feedparser._open_resource = constant(xkcd_new)
try:
with conf.supybot.plugins.RSS.initialAnnounceHeadlines.context(1):
with conf.supybot.plugins.RSS.sortFeedItems.context('newestFirst'):
self.assertNotError('rss add xkcd http://xkcd.com/rss.xml')
self.assertNotError('rss announce add xkcd')
self.assertRegexp(' ', 'Snake Facts')
finally:
self._feedMsg('rss announce remove xkcd')
self._feedMsg('rss remove xkcd')
feedparser._open_resource = old_open
def testInitialAnnounceOldest(self):
old_open = feedparser._open_resource
feedparser._open_resource = constant(xkcd_new)
try:
with conf.supybot.plugins.RSS.initialAnnounceHeadlines.context(1):
with conf.supybot.plugins.RSS.sortFeedItems.context('oldestFirst'):
self.assertNotError('rss add xkcd http://xkcd.com/rss.xml')
self.assertNotError('rss announce add xkcd')
self.assertRegexp(' ', 'Chaos')
finally:
self._feedMsg('rss announce remove xkcd')
self._feedMsg('rss remove xkcd')
feedparser._open_resource = old_open
def testNoInitialAnnounce(self):
old_open = feedparser._open_resource
feedparser._open_resource = constant(xkcd_old)
try: