Added arstechnica and advogato; restructured to make adding feeds quick and easy.

This commit is contained in:
Jeremy Fincher 2003-04-06 12:19:55 +00:00
parent 43c0de76d9
commit d625b56eae
1 changed files with 34 additions and 13 deletions

View File

@ -36,30 +36,51 @@ Add the module docstring here. This will be used by the setup.py script.
from baseplugin import *
import time
import operator
import rssparser
import privmsgs
import callbacks
def makeHeadlines(name, url, docstring, timeLimit=1800, title='title'):
timeAttr = '_%sTime' % name
responseAttr = '_%sResponse' % name
def f(self, irc, msg, args):
now = time.time()
if not hasattr(self, timeAttr) or \
now - getattr(self, timeAttr) > timeLimit:
results = rssparser.parse(url)
headlines = [x[title] for x in results['items']]
while reduce(operator.add, map(len, headlines)) > 350:
headlines.pop()
setattr(self, responseAttr, ' :: '.join(headlines))
setattr(self, timeAttr, now)
irc.reply(msg, getattr(self, responseAttr))
f.__doc__ = docstring
return f
class RSS(callbacks.Privmsg):
threaded = True
_slashdotTime = 0.0
def slashdot(self, irc, msg, args):
"""takes no arguments
slashdot = makeHeadlines('slashdot', 'http://slashdot.org/slashdot.rss',
"""takes no arguments
Returns the current headlines on slashdot.org, News for Nerds, Stuff
that Matters.
"""
if time.time() - self._slashdotTime > 1800:
results = rssparser.parse('http://slashdot.org/slashdot.rss')
headlines = [x['title'] for x in results['items']]
self._slashdotResponse = ' :: '.join(headlines)
while len(self._slashdotResponse) > 400:
headlines.pop()
self._slashdotResponse = ' :: '.join(headlines)
self._slashdotTime = time.time()
irc.reply(msg, self._slashdotResponse)
""")
arstechnica = makeHeadlines('arstechnica',
'http://arstechnica.com/etc/rdf/ars.rdf',
"""takes no arguments
Returns the current headlines on arstechnica.com, the pc enthusiast's
resource.
""")
advogato = makeHeadlines('advogato',
'http://advogato.org/rss/articles.xml',
"""takes no arguments
Returns the current headlines on advogato.org.
""")
Class = RSS