RSS: add option to strip url redirects from headlines

This commit is contained in:
Daniel Folkinshteyn 2013-05-04 00:01:52 -04:00
parent 02a2a056a4
commit 78659113c1
2 changed files with 9 additions and 1 deletions

View File

@ -62,6 +62,9 @@ conf.registerGlobalValue(RSS, 'waitPeriod',
registry.PositiveInteger(1800, """Indicates how many seconds the bot will registry.PositiveInteger(1800, """Indicates how many seconds the bot will
wait between retrieving RSS feeds; requests made within this period will wait between retrieving RSS feeds; requests made within this period will
return cached results.""")) return cached results."""))
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', conf.registerGlobalValue(RSS, 'feeds',
FeedNames([], """Determines what feeds should be accessible as FeedNames([], """Determines what feeds should be accessible as

View File

@ -33,6 +33,7 @@ import time
import socket import socket
import sgmllib import sgmllib
import threading import threading
import re
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
@ -143,9 +144,13 @@ class RSS(callbacks.Plugin):
if self.registryValue(config, channel): if self.registryValue(config, channel):
for headline in headlines: for headline in headlines:
if headline[1]: if headline[1]:
if self.registryValue('stripRedirect'):
h = re.sub('^.*http://', 'http://', headline[1])
else:
h = headline[1]
newheadlines.append(format('%s %u', newheadlines.append(format('%s %u',
headline[0], headline[0],
headline[1].encode('utf-8'))) h.encode('utf-8')))
else: else:
newheadlines.append(format('%s', headline[0])) newheadlines.append(format('%s', headline[0]))
else: else: