Created
December 10, 2013 01:11
-
-
Save hiilppp/7884176 to your computer and use it in GitHub Desktop.
Python script to manipulate text in Pythonista in the following manner and send the result (back) to Drafts: Sort lines, remove blank and duplicate lines, and prepend a hyphen to lines which don't start with one.
This file contains 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
# To call script from Drafts, use the follwing URL as URL Action: | |
# <pythonista://list.py?action=run&argv=[[draft]]> | |
import os | |
import re | |
import sys | |
import urllib | |
import webbrowser | |
a = re.sub(r"(?m)^[*-] ", "", sys.argv[1]) | |
a = set(a.split("\n")) | |
a = "".join([l + "\n" for l in a]) | |
a = os.linesep.join([s for s in a.split("\n") if s]) | |
a = a.split("\n") | |
a.sort(key=str.lower) | |
a = "\n".join(a) | |
a = re.sub(r"(?m)^", "- ", a) | |
webbrowser.open("drafts://x-callback-url/create?text=" + urllib.quote(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cf. sort.py.