From a453f56284f8b5da80a6cc8a003a515e07081bb9 Mon Sep 17 00:00:00 2001 From: James Vega Date: Wed, 4 Nov 2009 22:37:53 -0500 Subject: [PATCH] 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 --- plugins/ShrinkUrl/plugin.py | 13 +++++-------- plugins/ShrinkUrl/test.py | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/ShrinkUrl/plugin.py b/plugins/ShrinkUrl/plugin.py index 47e9cb66c..e47ae88cd 100644 --- a/plugins/ShrinkUrl/plugin.py +++ b/plugins/ShrinkUrl/plugin.py @@ -166,18 +166,15 @@ class ShrinkUrl(callbacks.PluginRegexp): irc.error(str(e)) ln = thread(wrap(ln, ['url'])) - _tinyRe = re.compile(r'
(http://tinyurl\.com/\w+)') def _getTinyUrl(self, url): try: return self.db.get('tiny', url) except KeyError: - s = utils.web.getUrl('http://tinyurl.com/create.php?url=' + url) - m = self._tinyRe.search(s) - if m is None: - raise ShrinkError, 'Could not parse the TinyURL.com results.' - tinyurl = m.group(1) - self.db.set('tiny', url, tinyurl) - return tinyurl + text = utils.web.getUrl('http://tinyurl.com/api-create.php?url=' + url) + if text.startswith('Error'): + raise ShrinkError, text[5:] + self.db.set('tiny', url, text) + return text def tiny(self, irc, msg, args, url): """ diff --git a/plugins/ShrinkUrl/test.py b/plugins/ShrinkUrl/test.py index 3b8bd7bf2..bae344175 100644 --- a/plugins/ShrinkUrl/test.py +++ b/plugins/ShrinkUrl/test.py @@ -32,7 +32,7 @@ from supybot.test import * class ShrinkUrlTestCase(ChannelPluginTestCase): plugins = ('ShrinkUrl',) - config = {'supybot.snarfThrottle': .5} + config = {'supybot.snarfThrottle': 0} sfUrl ='http://sourceforge.net/tracker/?func=add&group_id=58965&atid=48947' udUrl = 'http://www.urbandictionary.com/define.php?' \