-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskpaper.py
85 lines (63 loc) · 1.86 KB
/
taskpaper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
import subprocess
import sys
script = """tell application "TaskPaper"
tell front document
my proccess_exported_text(export with entries entries)
end tell
end tell
on proccess_exported_text(exported_text)
exported_text
end proccess_exported_text
"""
def make_headings(content):
# Handle Headings
p = subprocess.Popen(
['sed', 's/^\\([[:alnum:]][[:alnum:][:punct:][:blank:]]*\\):$/=== \\1 ===/'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
content, stderr = p.communicate(content)
# Add new lines around 'Projects'
p = subprocess.Popen(
['sed', 's/^=== .* ===$/\\\n&\\\n/'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
content, stderr = p.communicate(content)
# Replace tabs with spaces
p = subprocess.Popen(
['sed', 's/\t/ /g'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
content, stderr = p.communicate(content)
# Add an extra spance in front of all the lines that start with a
# dash (tasks)
p = subprocess.Popen(
['sed', 's/^[[:blank:]]*-.*$/ &/'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
content, stderr = p.communicate(content)
return content
def get_open_task_paper_doc_as_text():
p = subprocess.Popen(
['/usr/bin/osascript', '-'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = p.communicate(script)
if p.returncode != 0:
print(stderr)
sys.exit(p.returncode)
content = make_headings(stdout)
return content
if __name__ == "__main__":
content = get_open_task_paper_doc_as_text()
print(content)