mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 14:40:51 +01:00
Add a feedName converter
This commit is contained in:
parent
b697661a56
commit
3cb46ab765
@ -94,6 +94,14 @@ conf.registerChannelValue(conf.supybot.plugins.RSS.announce, 'showLinks',
|
|||||||
along with the title of the feed when a feed is automatically
|
along with the title of the feed when a feed is automatically
|
||||||
announced."""))
|
announced."""))
|
||||||
|
|
||||||
|
def getFeedName(irc, msg, args, state):
|
||||||
|
if not registry.isValidRegistryName(args[0]):
|
||||||
|
irc.errorInvalid('feed name', name,
|
||||||
|
'Feed names must not include spaces.')
|
||||||
|
state.args.append(callbacks.canonicalName(args.pop(0)))
|
||||||
|
|
||||||
|
addConverter('feedName', getFeedName)
|
||||||
|
|
||||||
class RSS(callbacks.Privmsg):
|
class RSS(callbacks.Privmsg):
|
||||||
"""This plugin is useful both for announcing updates to RSS feeds in a
|
"""This plugin is useful both for announcing updates to RSS feeds in a
|
||||||
channel, and for retrieving the headlines of RSS feeds via command. Use
|
channel, and for retrieving the headlines of RSS feeds via command. Use
|
||||||
@ -270,11 +278,6 @@ class RSS(callbacks.Privmsg):
|
|||||||
headlines.append((title, None))
|
headlines.append((title, None))
|
||||||
return headlines
|
return headlines
|
||||||
|
|
||||||
def _validFeedName(self, name):
|
|
||||||
if not registry.isValidRegistryName(name):
|
|
||||||
raise ValueError, name
|
|
||||||
return callbacks.canonicalName(name)
|
|
||||||
|
|
||||||
def makeFeedCommand(self, name, url):
|
def makeFeedCommand(self, name, url):
|
||||||
docstring = """[<number of headlines>]
|
docstring = """[<number of headlines>]
|
||||||
|
|
||||||
@ -284,7 +287,6 @@ class RSS(callbacks.Privmsg):
|
|||||||
seconds, which defaults to 1800 (30 minutes) since that's what most
|
seconds, which defaults to 1800 (30 minutes) since that's what most
|
||||||
websites prefer.
|
websites prefer.
|
||||||
""" % (name, url)
|
""" % (name, url)
|
||||||
assert name == self._validFeedName(name)
|
|
||||||
if url not in self.locks:
|
if url not in self.locks:
|
||||||
self.locks[url] = threading.RLock()
|
self.locks[url] = threading.RLock()
|
||||||
if hasattr(self.__class__, name) and \
|
if hasattr(self.__class__, name) and \
|
||||||
@ -306,14 +308,9 @@ class RSS(callbacks.Privmsg):
|
|||||||
Adds a command to this plugin that will look up the RSS feed at the
|
Adds a command to this plugin that will look up the RSS feed at the
|
||||||
given URL.
|
given URL.
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
name = self._validFeedName(name)
|
|
||||||
except ValueError:
|
|
||||||
irc.errorInvalid('feed name', name, 'Feed names must not '
|
|
||||||
'include dots, colons, or spaces.')
|
|
||||||
self.makeFeedCommand(name, url)
|
self.makeFeedCommand(name, url)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
add = wrap(add, ['something', 'url'])
|
add = wrap(add, ['feedName', 'url'])
|
||||||
|
|
||||||
def remove(self, irc, msg, args, name):
|
def remove(self, irc, msg, args, name):
|
||||||
"""<name>
|
"""<name>
|
||||||
@ -328,7 +325,7 @@ class RSS(callbacks.Privmsg):
|
|||||||
delattr(self.__class__, name)
|
delattr(self.__class__, name)
|
||||||
conf.supybot.plugins.RSS.feeds.unregister(name)
|
conf.supybot.plugins.RSS.feeds.unregister(name)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
remove = wrap(remove, ['commandName'])
|
remove = wrap(remove, ['feedName'])
|
||||||
|
|
||||||
def announce(self, irc, msg, args, channel, optlist, rest):
|
def announce(self, irc, msg, args, channel, optlist, rest):
|
||||||
"""[<channel>] [--remove] [<name|url> ...]
|
"""[<channel>] [--remove] [<name|url> ...]
|
||||||
@ -369,7 +366,8 @@ class RSS(callbacks.Privmsg):
|
|||||||
irc.reply(feeds or 'I am currently not announcing any feeds.')
|
irc.reply(feeds or 'I am currently not announcing any feeds.')
|
||||||
return
|
return
|
||||||
announce = wrap(announce, [('checkChannelCapability', 'op'),
|
announce = wrap(announce, [('checkChannelCapability', 'op'),
|
||||||
getopts({'remove':''}), any('something')])
|
getopts({'remove':''}),
|
||||||
|
any(first('url', 'feedName'))])
|
||||||
|
|
||||||
def rss(self, irc, msg, args, url, n):
|
def rss(self, irc, msg, args, url, n):
|
||||||
"""<url> [<number of headlines>]
|
"""<url> [<number of headlines>]
|
||||||
@ -417,7 +415,7 @@ class RSS(callbacks.Privmsg):
|
|||||||
now = time.mktime(time.gmtime())
|
now = time.mktime(time.gmtime())
|
||||||
when = utils.timeElapsed(now - seconds) + ' ago'
|
when = utils.timeElapsed(now - seconds) + ' ago'
|
||||||
else:
|
else:
|
||||||
when = "time unavailable"
|
when = 'time unavailable'
|
||||||
# The rest of the entries are all available in the channel key
|
# The rest of the entries are all available in the channel key
|
||||||
response = 'Title: %s; URL: <%s>; ' \
|
response = 'Title: %s; URL: <%s>; ' \
|
||||||
'Description: %s; Last updated %s.' % (
|
'Description: %s; Last updated %s.' % (
|
||||||
@ -426,7 +424,7 @@ class RSS(callbacks.Privmsg):
|
|||||||
info.get('description', 'unavailable').strip(),
|
info.get('description', 'unavailable').strip(),
|
||||||
when)
|
when)
|
||||||
irc.reply(' '.join(response.split()))
|
irc.reply(' '.join(response.split()))
|
||||||
info = wrap(info, ['something'])
|
info = wrap(info, [first('url', 'feedName')])
|
||||||
|
|
||||||
|
|
||||||
Class = RSS
|
Class = RSS
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
from testsupport import *
|
from testsupport import *
|
||||||
|
|
||||||
url = 'http://www.advogato.org/rss/articles.xml'
|
url = 'http://www.advogato.org/rss/articles.xml'
|
||||||
class RSSTestCase(PluginTestCase, PluginDocumentation):
|
class RSSTestCase(ChannelPluginTestCase):
|
||||||
plugins = ('RSS',)
|
plugins = ('RSS',)
|
||||||
def testRssAddBadName(self):
|
def testRssAddBadName(self):
|
||||||
self.assertError('rss add "foo bar" %s' % url)
|
self.assertError('rss add "foo bar" %s' % url)
|
||||||
@ -45,6 +45,9 @@ class RSSTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
def testRssinfo(self):
|
def testRssinfo(self):
|
||||||
self.assertNotError('rss info %s' % url)
|
self.assertNotError('rss info %s' % url)
|
||||||
self.assertNotError('rss add advogato %s' % url)
|
self.assertNotError('rss add advogato %s' % url)
|
||||||
|
# For some reason conf.supybot.plugins.RSS.feeds.advogato is
|
||||||
|
# empty, which is why this test is failing. Works in practice,
|
||||||
|
# but not here. :(
|
||||||
self.assertNotError('rss info advogato')
|
self.assertNotError('rss info advogato')
|
||||||
self.assertNotError('rss info AdVogATo')
|
self.assertNotError('rss info AdVogATo')
|
||||||
self.assertNotError('rss remove advogato')
|
self.assertNotError('rss remove advogato')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user