Pythonista Trick: URL to Markdown
by Peter Bijkerk
http://www.macdrifter.com/uploads/2012/09/2012-09-13%2018.37.05_600px.png
Here’s a nice little tool I made in Pythonista for iOS (review). This script is using Brett Terpstra’s awesome heckyesmarkdown web service, which is extremely useful and underrated.
To use this script, I copy a URL to the iOS clipboard and jump into Pythonista. I trigger this script to get the web page in Markdown encoded text.
This URL: http://www.macdrifter.com/2012/09/nfc-is-a-crutch.html
is turned into plain text and put back on the clipboard. The results are displayed in a popup Pythonista browser window:
Here’s the script:
import clipboard import urllib2 import webbrowser clipString = clipboard.get() marky = 'http://heckyesmarkdown.com/go/?u=' queryString = marky + clipString reqMD = urllib2.Request(queryString) openMD = urllib2.urlopen(reqMD) content = (openMD.read().decode('utf-8')) clipboard.set(content) webbrowser.open(queryString)
The script started life with a mess of URL validations steps, but Brett’s service is so awesome that it just fails gracefully with bad URL’s. But I did try out the new Pythonista console.alert() method. I like it.
via Macdrifter http://www.macdrifter.com/2012/09/pythonista-trick-url-to-markdown.html