mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 22:24:20 +01:00
ShrinkUrl: Use tinyurl's api-create page to avoid screen-scraping.
Set snarfThrottle to 0 while testing since we know there's nothing other than the test input that could be causing us to snarf. Fixes some intermittent test failures due to fast snarf responses. Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
parent
eda8ce3aa0
commit
a453f56284
@ -166,18 +166,15 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
ln = thread(wrap(ln, ['url']))
|
ln = thread(wrap(ln, ['url']))
|
||||||
|
|
||||||
_tinyRe = re.compile(r'<blockquote><b>(http://tinyurl\.com/\w+)</b>')
|
|
||||||
def _getTinyUrl(self, url):
|
def _getTinyUrl(self, url):
|
||||||
try:
|
try:
|
||||||
return self.db.get('tiny', url)
|
return self.db.get('tiny', url)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
s = utils.web.getUrl('http://tinyurl.com/create.php?url=' + url)
|
text = utils.web.getUrl('http://tinyurl.com/api-create.php?url=' + url)
|
||||||
m = self._tinyRe.search(s)
|
if text.startswith('Error'):
|
||||||
if m is None:
|
raise ShrinkError, text[5:]
|
||||||
raise ShrinkError, 'Could not parse the TinyURL.com results.'
|
self.db.set('tiny', url, text)
|
||||||
tinyurl = m.group(1)
|
return text
|
||||||
self.db.set('tiny', url, tinyurl)
|
|
||||||
return tinyurl
|
|
||||||
|
|
||||||
def tiny(self, irc, msg, args, url):
|
def tiny(self, irc, msg, args, url):
|
||||||
"""<url>
|
"""<url>
|
||||||
|
@ -32,7 +32,7 @@ from supybot.test import *
|
|||||||
|
|
||||||
class ShrinkUrlTestCase(ChannelPluginTestCase):
|
class ShrinkUrlTestCase(ChannelPluginTestCase):
|
||||||
plugins = ('ShrinkUrl',)
|
plugins = ('ShrinkUrl',)
|
||||||
config = {'supybot.snarfThrottle': .5}
|
config = {'supybot.snarfThrottle': 0}
|
||||||
|
|
||||||
sfUrl ='http://sourceforge.net/tracker/?func=add&group_id=58965&atid=48947'
|
sfUrl ='http://sourceforge.net/tracker/?func=add&group_id=58965&atid=48947'
|
||||||
udUrl = 'http://www.urbandictionary.com/define.php?' \
|
udUrl = 'http://www.urbandictionary.com/define.php?' \
|
||||||
|
Loading…
Reference in New Issue
Block a user