Skip to content

Commit

Permalink
ShrinkUrl: Use tinyurl's api-create page to avoid screen-scraping.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jamessan committed Nov 5, 2009
1 parent eda8ce3 commit a453f56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions plugins/ShrinkUrl/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,15 @@ def ln(self, irc, msg, args, url):
irc.error(str(e))
ln = thread(wrap(ln, ['url']))

_tinyRe = re.compile(r'<blockquote><b>(http://tinyurl\.com/\w+)</b>')
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):
"""<url>
Expand Down
2 changes: 1 addition & 1 deletion plugins/ShrinkUrl/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

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?' \
Expand Down

0 comments on commit a453f56

Please sign in to comment.