Skip to content

Instantly share code, notes, and snippets.

@omz
Created May 17, 2013 04:17
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save omz/5596891 to your computer and use it in GitHub Desktop.
Save omz/5596891 to your computer and use it in GitHub Desktop.
ShortURL
# Simple URL shortener using is.gd
#
# Save this script as 'ShortURL' in Pythonista and add the
# bookmarklet below to Safari. The result is copied to the clipboard.
# Bookmarklet:
# javascript:window.location.href='pythonista://ShortURL?action=run&argv='+encodeURIComponent(window.location.href);
import clipboard
import re
import sys
long_url = sys.argv[1]
if long_url is not None and re.match('http(s)?://.*', long_url):
import urllib
short_url = urllib.urlopen('http://is.gd/create.php?format=simple&url=' + urllib.quote(long_url, '')).read()
if re.match('http://is.gd.*', short_url):
clipboard.set(short_url)
import webbrowser
webbrowser.open('safari-' + long_url)
else:
print 'Error:', short_url
else:
print 'Invalid/missing URL argument.'
@jothirams
Copy link

Works great. As I use iCab as my primary browser, I have modified this gist slightly to open it in iCab. You can find it in https://gist.github.com/jothirams/efa000dab1025aa5ba24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment