Jake.codes

Twitter to Tweetbot, for Pythonista

Sunday, October 27, 2013

# Twitter to Tweetbot
# as a Pythonista JavaScript bookmarklet
# 
# This is a minor change to Federico Viticci's
# script from:
# http://www.macstories.net/tutorials/convert-twitter-com-urls-to-tweetbot-links/
#
# Bookmarklet:
# javascript:location.href='pythonista://TwitterToTweetbot?action=run&argv='+encodeURIComponent(location.href);
#
import sys
import console
import webbrowser

mytext = sys.argv[1]
mytext = mytext.replace('https://twitter.com/', 'tweetbot://')
mytext = mytext.replace('statuses', 'status')
mytext = mytext.replace('http://twitter.com/', 'tweetbot://')
mytext = mytext.replace('http://mobile.twitter.com/', 'tweetbot://')
mytext = mytext.replace('https://mobile.twitter.com/', 'tweetbot://')

console.clear()
print mytext

webbrowser.open(mytext)