h/plugins/tinyurl.py

18 lines
377 B
Python
Raw Normal View History

2009-05-22 00:12:35 +00:00
import re
2009-05-22 00:24:01 +00:00
import urllib2
2009-05-22 00:12:35 +00:00
import hook
2009-05-22 00:24:01 +00:00
tinyurl_re = re.compile(r'http://(?:www\.)?tinyurl.com/([A-Za-z0-9\-]+)', flags=re.IGNORECASE)
2009-05-22 00:12:35 +00:00
@hook.command(hook=r'(.*)', prefix=False)
def tinyurl(inp):
tumatch = tinyurl_re.search(inp)
2009-05-22 00:24:01 +00:00
if tumatch:
try:
return urllib2.urlopen(tumatch.group()).url.strip()
except urllib2.URLError:
pass