Created
March 15, 2018 16:26
-
-
Save kbro237/5efe51aeb0574b8d98c9c68d50f11ee0 to your computer and use it in GitHub Desktop.
Script and template example I use to go from a taskpaper template to to a project I can paste directly into OmniFocus
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
- wrote ${month} council report @parallel(false) @context(office) | |
- check Council Planning folder @context(office) @defer(${date_of_meeting} -6d +9h) | |
- check 'council' context in OmniFocus @context(anywhere) @defer(${date_of_meeting} -6d +9h) | |
- use cal & OF to write report to council @context(mac) @defer(${date_of_meeting} -6d +9h) | |
- save report as PDF @context(mac) @defer(${date_of_meeting} -6d +9h) | |
- email report to council @context(email) @defer(${date_of_meeting} -6d +9h) | |
- archive old data in OF @context(mac) @defer(${date_of_meeting} -6d +9h) | |
- prepare Council devotions @context(office) @defer(${date_of_meeting} -6d +9h) |
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
#!/usr/bin/env python3 | |
from string import Template | |
import sys | |
import re | |
import subprocess | |
incoming = sys.argv[1] | |
def get_template(incoming): | |
tfile = open(str(incoming), 'r') | |
t = Template(tfile.read()) | |
return t | |
def get_placeholders(t): | |
placetuples = re.findall(pattern=t.pattern, string=t.template) | |
placeholders = [] | |
for i in placetuples: | |
if len(i) != 0: | |
for x in i: | |
if len(x) != 0 and x not in placeholders: | |
placeholders.append(x) | |
return placeholders | |
def get_values(placeholders): | |
d = {} | |
for p in placeholders: | |
value = input(p + ': ') | |
d.update({p: value}) | |
return d | |
def getClipboardData(): | |
p = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE) | |
data = p.stdout.read() | |
return data | |
def setClipboardData(data): | |
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE) | |
p.stdin.write(data) | |
p.stdin.close() | |
def ask_to_copy(a): | |
r = input("Copy to clipboard ([y]/n)? ") | |
if r == 'y': | |
setClipboardData(a) | |
if len(r) == 0: | |
setClipboardData(a) | |
else: | |
pass | |
def main(): | |
t = get_template(incoming) | |
p = get_placeholders(t) | |
d = get_values(p) | |
m = t.safe_substitute(d) | |
print(m) | |
ask_to_copy(str.encode(m)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment