uggboots = babby
This commit is contained in:
parent
4358a4cc62
commit
d485958f93
|
@ -1,35 +1,17 @@
|
||||||
import socket
|
|
||||||
import re
|
import re
|
||||||
import locale
|
import urllib2
|
||||||
|
|
||||||
import hook
|
import hook
|
||||||
|
|
||||||
locale.setlocale(locale.LC_ALL, "")
|
|
||||||
|
|
||||||
def recv_basic(the_socket):
|
tinyurl_re = re.compile(r'http://(?:www\.)?tinyurl.com/([A-Za-z0-9\-]+)', flags=re.IGNORECASE)
|
||||||
total_data=[]
|
|
||||||
while True:
|
|
||||||
data = the_socket.recv(8192)
|
|
||||||
if not data: break
|
|
||||||
total_data.append(data)
|
|
||||||
return ''.join(total_data)
|
|
||||||
|
|
||||||
|
|
||||||
def tinyurlparse(url):
|
|
||||||
id = url[(url.rfind("/",8)+1):]
|
|
||||||
ts = socket.socket()
|
|
||||||
ts.connect(("tinyurl.com", 80))
|
|
||||||
ts.send("GET /redirect.php?num=%s HTTP/1.1\r\n" % id)
|
|
||||||
ts.send("Host: tinyurl.com\r\n\r\n");
|
|
||||||
tresult = recv_basic(ts);
|
|
||||||
for tline in tresult.split("\n"):
|
|
||||||
if tline[:10] == "Location: ":
|
|
||||||
return tline[10:]
|
|
||||||
|
|
||||||
tinyurl_re = re.compile(r'http://(www\.)?tinyurl.com/([A-Za-z0-9\-]+)', flags=re.IGNORECASE)
|
|
||||||
|
|
||||||
@hook.command(hook=r'(.*)', prefix=False)
|
@hook.command(hook=r'(.*)', prefix=False)
|
||||||
def tinyurl(inp):
|
def tinyurl(inp):
|
||||||
tumatch = tinyurl_re.search(inp)
|
tumatch = tinyurl_re.search(inp)
|
||||||
if (tumatch is not None):
|
if tumatch:
|
||||||
return tinyurlparse(tumatch.group())
|
try:
|
||||||
|
return urllib2.urlopen(tumatch.group()).url.strip()
|
||||||
|
except urllib2.URLError:
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue