Skip to content

Instantly share code, notes, and snippets.

@ifduyue
Created December 18, 2011 05:46
Show Gist options
  • Save ifduyue/1492493 to your computer and use it in GitHub Desktop.
Save ifduyue/1492493 to your computer and use it in GitHub Desktop.
shurl_shorten
$ 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
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