Last active
February 19, 2024 22:24
-
-
Save KelSolaar/8df974c66f93f8c4b9de46a0b22584a6 to your computer and use it in GitHub Desktop.
Omnifocus Taskpaper Export to Org-Mode
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 python | |
# -*- coding: utf-8 -*- | |
""" | |
Converts from *Omnifocus* *taskpaper* export to *org-mode*. | |
Examples | |
-------- | |
> python taskpaper2org.py omnifocus.txt > omnifocus.org | |
Notes | |
----- | |
- Needs a good refactoring but does the work for my use case. | |
""" | |
import re | |
import sys | |
def taskpaper2org(taskpaper_file_path): | |
with open(taskpaper_file_path, 'r') as taskpaper_file: | |
taskpaper_content = taskpaper_file.readlines() | |
for line in taskpaper_content: | |
line = line.rstrip() | |
task_match = re.match('^(\t*)-(.*?)((@\w+\(.*))*$', line) | |
uncategorised_match = re.match('^(\t*)(.*)$', line) | |
if task_match: | |
indentation = len(task_match.group(1)) + 1 | |
org_line = '{0} {1}'.format('*' * indentation, | |
task_match.group(2).strip()) | |
if task_match.group(3): | |
tags_match = re.findall('@(\w+)\((.*?)\)', | |
task_match.group(3)) | |
for tag in reversed(tags_match): | |
if tag[0] == 'done': | |
org_line = '{0} DONE {1}'.format( | |
'*' * indentation, task_match.group(2).strip()) | |
print(org_line) | |
print('{0}CLOSED: [{1}]'.format( | |
' ' * (indentation + 1), tag[1])) | |
break | |
elif tag[0] in ('defer' or 'due'): | |
org_line = '{0} TODO {1}'.format( | |
'*' * indentation, task_match.group(2).strip()) | |
print(org_line) | |
print('{0}DEADLINE: [{1}]'.format( | |
' ' * (indentation + 1), tag[1])) | |
break | |
else: | |
org_line = '{0} TODO {1}'.format( | |
'*' * indentation, task_match.group(2).strip()) | |
print(org_line) | |
break | |
else: | |
print(org_line) | |
else: | |
indentation = len(uncategorised_match.group(1)) + 1 | |
org_line = '{0}{1}'.format( | |
' ' * indentation, uncategorised_match.group(2).rstrip()) | |
print(org_line) | |
if __name__ == '__main__': | |
taskpaper2org(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment