Last active
December 12, 2015 09:29
-
-
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.
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
""" | |
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