From e4ddda4aebcb73a9e9107011a3f9615039dcd756 Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Sat, 4 May 2013 00:01:52 -0400 Subject: [PATCH] RSS: add option to strip url redirects from headlines Conflicts: plugins/RSS/config.py --- plugins/RSS/config.py | 3 +++ plugins/RSS/plugin.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/RSS/config.py b/plugins/RSS/config.py index 93c9f2f8b..c1e1d53e5 100644 --- a/plugins/RSS/config.py +++ b/plugins/RSS/config.py @@ -75,6 +75,9 @@ conf.registerGlobalValue(RSS, 'sortFeedItems', FeedItemSortOrder('asInFeed', _("""Determines whether feed items should be sorted by their update timestamp or kept in the same order as they appear in a feed."""))) +conf.registerGlobalValue(RSS, 'stripRedirect', registry.Boolean( + True, """Determines whether the bot will attempt to strip url redirection + from headline links, by taking things after the last http://.""")) conf.registerGlobalValue(RSS, 'feeds', FeedNames([], _("""Determines what feeds should be accessible as diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 237458b84..2e2bee63e 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -32,6 +32,7 @@ import time import types import socket import threading +import re import supybot.conf as conf import supybot.utils as utils @@ -145,9 +146,13 @@ class RSS(callbacks.Plugin): if self.registryValue(config, channel): for headline in headlines: if headline[1]: + if self.registryValue('stripRedirect'): + h = re.sub('^.*http://', 'http://', headline[1]) + else: + h = headline[1] newheadlines.append(format('%s %u', headline[0], - headline[1].encode('utf-8'))) + h.encode('utf-8'))) else: newheadlines.append(format('%s', headline[0])) else: