Skip to content

Instantly share code, notes, and snippets.

@voidfiles
Last active December 12, 2015 09:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voidfiles/4751549 to your computer and use it in GitHub Desktop.
Save voidfiles/4751549 to your computer and use it in GitHub Desktop.
I wanted to share clean URL's directly from my phone. This is most specifically geared towards feedburner URL's, but could be just short URL's as well. This script unwraps any URL's surrounded with ** in the text on your clipboard. Unwraps them, and clears out unwanted query params. Then opens the text in felix for posting.
"""
Pythonist script to expand any URL surrounded by **'s
"""
import clipboard
import requests
import webbrowser
import urlparse
from urllib import quote, urlencode
blacklist_query_params = ['utm_campaign', 'utm_source', 'utm_medium']
text = clipboard.get()
if text == '':
print 'No text in clipboard'
if '**' in text:
start, url, end = text.split('**')
resp = requests.get(url)
if resp.ok:
url = resp.url
parts = urlparse.urlsplit(url)
query = urlparse.parse_qs(parts.query)
for bkey in blacklist_query_params:
try:
del query[bkey]
except KeyError:
pass
parts = list(parts)
parts[3] = urlencode(query)
url = urlparse.urlunsplit(parts)
text = ''.join([start, url, end])
q = quote(text)
webbrowser.open('felix://compose/post?text=' + q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment