Created
May 17, 2013 04:17
-
-
Save omz/5596891 to your computer and use it in GitHub Desktop.
ShortURL
This file contains hidden or 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
# 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.' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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