-
-
Save jothirams/efa000dab1025aa5ba24 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/iCab. The result is copied to the clipboard. | |
# The original script opens the longURL in Safari - You can find it from https://gist.github.com/omz/5596891 | |
# This scripts opens it back in iCab. | |
# 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('x-icabmobile://x-callback-url/open?url=' + 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