Created
December 18, 2011 05:46
-
-
Save ifduyue/1492493 to your computer and use it in GitHub Desktop.
shurl_shorten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat ~/bin/shurl | |
#!/bin/bash | |
curl -i http://shurl.im/ -F "url=$1" -s | grep Location | awk '{print $2}' | |
$ shurl http://lyxint.com/ | |
http://shurl.im/1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def shurl(url): | |
from urlfetch import post | |
try: | |
response = post("http://shurl.im/", data={'url': url}, timeout=3) | |
url = response.getheader('location', url) | |
except: pass | |
return url | |
def shurl_status(status): | |
import re | |
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F[0-9a-fA-F]))+', status) | |
for url in urls: | |
s = shurl(url) | |
status = status.replace(url, s) | |
return status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment