mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Added arstechnica and advogato; restructured to make adding feeds quick and easy.
This commit is contained in:
parent
43c0de76d9
commit
d625b56eae
@ -36,30 +36,51 @@ Add the module docstring here. This will be used by the setup.py script.
|
|||||||
from baseplugin import *
|
from baseplugin import *
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import operator
|
||||||
|
|
||||||
import rssparser
|
import rssparser
|
||||||
|
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
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):
|
class RSS(callbacks.Privmsg):
|
||||||
threaded = True
|
threaded = True
|
||||||
_slashdotTime = 0.0
|
slashdot = makeHeadlines('slashdot', 'http://slashdot.org/slashdot.rss',
|
||||||
def slashdot(self, irc, msg, args):
|
"""takes no arguments
|
||||||
"""takes no arguments
|
|
||||||
|
|
||||||
Returns the current headlines on slashdot.org, News for Nerds, Stuff
|
Returns the current headlines on slashdot.org, News for Nerds, Stuff
|
||||||
that Matters.
|
that Matters.
|
||||||
"""
|
""")
|
||||||
if time.time() - self._slashdotTime > 1800:
|
arstechnica = makeHeadlines('arstechnica',
|
||||||
results = rssparser.parse('http://slashdot.org/slashdot.rss')
|
'http://arstechnica.com/etc/rdf/ars.rdf',
|
||||||
headlines = [x['title'] for x in results['items']]
|
"""takes no arguments
|
||||||
self._slashdotResponse = ' :: '.join(headlines)
|
|
||||||
while len(self._slashdotResponse) > 400:
|
Returns the current headlines on arstechnica.com, the pc enthusiast's
|
||||||
headlines.pop()
|
resource.
|
||||||
self._slashdotResponse = ' :: '.join(headlines)
|
""")
|
||||||
self._slashdotTime = time.time()
|
advogato = makeHeadlines('advogato',
|
||||||
irc.reply(msg, self._slashdotResponse)
|
'http://advogato.org/rss/articles.xml',
|
||||||
|
"""takes no arguments
|
||||||
|
|
||||||
|
Returns the current headlines on advogato.org.
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
Class = RSS
|
Class = RSS
|
||||||
|
Loading…
Reference in New Issue
Block a user