mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 14:14:37 +01:00
Totally changed interface and added configure.
This commit is contained in:
parent
11ae9119ba
commit
6adf5cf04b
@ -30,7 +30,21 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Add the module docstring here. This will be used by the setup.py script.
|
Provides basic functionality for handling RSS/RDF feeds. Depends on the Alias
|
||||||
|
module for user-friendliness: instead of:
|
||||||
|
|
||||||
|
rsstitles http://slashdot.org/slashdot.rss
|
||||||
|
|
||||||
|
It'll make the alias:
|
||||||
|
|
||||||
|
alias slashdot rsstitles http://slashdot.org/slashdot.rss
|
||||||
|
|
||||||
|
And you'll be able to call the command like this:
|
||||||
|
|
||||||
|
slashdot
|
||||||
|
|
||||||
|
Commands include:
|
||||||
|
rsstitles
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from baseplugin import *
|
from baseplugin import *
|
||||||
@ -43,44 +57,49 @@ import rssparser
|
|||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
|
|
||||||
def makeHeadlines(name, url, docstring, timeLimit=1800, title='title'):
|
def configure(onStart, afterConnect, advanced):
|
||||||
timeAttr = '_%sTime' % name
|
from questions import expect, anything, something, yn
|
||||||
responseAttr = '_%sResponse' % name
|
onStart.append('load RSS')
|
||||||
def f(self, irc, msg, args):
|
if yn('RSS depends on the Alias module. Is that module loaded?') == 'n':
|
||||||
now = time.time()
|
if yn('Do you want to load that module now?') == 'y':
|
||||||
if not hasattr(self, timeAttr) or \
|
onStart.append('load Alias')
|
||||||
now - getattr(self, timeAttr) > timeLimit:
|
else:
|
||||||
results = rssparser.parse(url)
|
print 'You can still use the RSS module, but you won\'t be asked'
|
||||||
headlines = [x[title] for x in results['items']]
|
print 'any further questions.'
|
||||||
while reduce(operator.add, map(len, headlines)) > 350:
|
return
|
||||||
headlines.pop()
|
prompt = 'Would you like to add an RSS feed?'
|
||||||
setattr(self, responseAttr, ' :: '.join(headlines))
|
while yn(prompt) == 'y':
|
||||||
setattr(self, timeAttr, now)
|
prompt = 'Would you like to add another RSS feed?'
|
||||||
irc.reply(msg, getattr(self, responseAttr))
|
name = anything('What\'s the name of the website?')
|
||||||
f.__doc__ = docstring
|
url = anything('What\'s the URL of the RSS feed?')
|
||||||
return f
|
onStart.append('alias %s "rsstitles %s"' % (name, url))
|
||||||
|
|
||||||
|
|
||||||
class RSS(callbacks.Privmsg):
|
class RSS(callbacks.Privmsg):
|
||||||
threaded = True
|
threaded = True
|
||||||
slashdot = makeHeadlines('slashdot', 'http://slashdot.org/slashdot.rss',
|
def __init__(self):
|
||||||
"""takes no arguments
|
callbacks.Privmsg.__init__(self)
|
||||||
|
self.lastRequest = {}
|
||||||
|
self.responses = {}
|
||||||
|
|
||||||
Returns the current headlines on slashdot.org, News for Nerds, Stuff
|
def rsstitles(self, irc, msg, args):
|
||||||
that Matters.
|
"""<url>
|
||||||
""")
|
|
||||||
arstechnica = makeHeadlines('arstechnica',
|
|
||||||
'http://arstechnica.com/etc/rdf/ars.rdf',
|
|
||||||
"""takes no arguments
|
|
||||||
|
|
||||||
Returns the current headlines on arstechnica.com, the pc enthusiast's
|
Gets the title components of the given RSS feed.
|
||||||
resource.
|
"""
|
||||||
""")
|
url = privmsgs.getArgs(args)
|
||||||
advogato = makeHeadlines('advogato',
|
now = time.time()
|
||||||
'http://advogato.org/rss/articles.xml',
|
if url not in self.lastRequest or now - self.lastRequest[url] > 1800:
|
||||||
"""takes no arguments
|
results = rssparser.parse(url)
|
||||||
|
headlines = [d['title'] for d in results['items']]
|
||||||
Returns the current headlines on advogato.org.
|
while reduce(operator.add, map(len, headlines), 0) > 350:
|
||||||
""")
|
headlines.pop()
|
||||||
|
if not headlines:
|
||||||
|
irc.error(msg, 'Error grabbing RSS feed')
|
||||||
|
return
|
||||||
|
self.responses[url] = ' :: '.join(headlines)
|
||||||
|
self.lastRequest[url] = now
|
||||||
|
irc.reply(msg, self.responses[url])
|
||||||
|
|
||||||
|
|
||||||
Class = RSS
|
Class = RSS
|
||||||
|
Loading…
Reference in New Issue
Block a user