Skip to content

Instantly share code, notes, and snippets.

@ChewingPencils
Last active December 14, 2015 19:09
Show Gist options
  • Save ChewingPencils/5134533 to your computer and use it in GitHub Desktop.
Save ChewingPencils/5134533 to your computer and use it in GitHub Desktop.
A Drafts app action to create a Quotebook app entry.
# Sean Korzdorfer
# 2013-03-10
# quote_bits.py
#
# Creates and submits a Quotebook app URL.
#
# [Quotebook](http://quotebookapp.com/)
# [Drafts](http://agiletortoise.com/drafts)
# [Pythonista](http://omz-software.com/pythonista/)
#
# Documentation: http://www.seankorzdorfer.com/open_notebook/quote%20bits%20for%20quotebook.html
#
# ## Install ##
#
# 1. Copy this script into a new Pythonista file. Name it quote_bits
# 2. Drafts Import Action URL:
# drafts://x-callback-url/import_action?type=URL&name=Quotebook%20~%20Quote%20Bits&url=pythonista://quote_bits?action=run&argv=[[draft]]
# Drafts URL Action:
# pythonista://quote_bits?action=run&argv=[[draft]]
import sys
import urllib
import webbrowser
import console
def main():
quoteBits = sys.argv[1].split('\n')
print '\nStarted: quote_bits'
if len(quoteBits) > 4:
print 'ERROR: Too Many Lines Recieved. You\'re Draft can only contain 4 lines.\nFinished: quote_bits'
return
if quoteBits[0] == '':
print '\nERROR: The First Line Can Not Be Blank.\nFinished: quote_bits'
return
webbrowser.open(parseBits(quoteBits))
def parseBits(quoteBits):
quoteURL = 'quotebook://add?quote=' + urllib.quote(quoteBits[0])
if len(quoteBits) >= 2 and quoteBits[1] != '':
quoteURL = quoteURL + '&author=' + urllib.quote(quoteBits[1])
if len(quoteBits) >= 3 and quoteBits[2] != '':
quoteURL = quoteURL + '&source=' + urllib.quote(quoteBits[2])
if len(quoteBits) == 4 and quoteBits[3] != '':
quoteURL = quoteURL + '&rating=' + urllib.quote(quoteBits[3])
print 'Quotebook URL Crafted: ' + quoteURL + '\nFinished: quote_bits'
return quoteURL
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment