Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert todo.txt or Taskpaper(Omnifocus) to .eml file. Then import into alpine.
# -*- coding: utf-8
"""
Manually Pre-process
## Omnifocus 拷贝为Taskpaper
把Taskpaper转成Todo.txt
VIM COMMANDS:
:%g/^$/d
:%s/@autodone(false)//g
:%s/@parallel(true)//g
:%s/@context(\(.*\))/@\1/g
:%s/@defer(\(.*\) .*)/t:\1 /g
:%s/@due(\(.*\) .*)/due:\1 /g
"""
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import sys
import re
with open(sys.argv[-1]) as f:
lines = f.readlines()
_subject = ""
_comment = []
for i, l in enumerate(lines):
if l.startswith("- "):
_subject = re.sub(r'^- ', '', l)
_subject = _subject.replace('\r','').replace('\n','')
elif l.startswith((" ","\t")):
_comment.append(l.strip().decode('utf-8'))
if i+1 < len(lines):
if lines[i+1].startswith("- "):
_output = True
else:
_output = False #not yet, wait for it..
else: #the last line, output anyway
_output = True
if _output:
_email = MIMEMultipart('alternative')
_email['Subject']=_subject.decode('utf-8')
_email['From']="todo@scateu.me"
_part= MIMEText(u'\n\r'.join(_comment)+u"\n\r-- \n\rImported from Taskpaper","plain","utf-8")
_email.attach(_part)
print _email
_subject = ""
_comment = []
# -*- coding: utf-8
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import sys
with open(sys.argv[-1]) as f:
lines = f.readlines()
for l in lines:
_email = MIMEMultipart('alternative')
_email['Subject']=l.replace('\r','').replace('\n','').decode('utf-8')
_email['From']="todo@scateu.me"
_part= MIMEText(u"Imported from todo.txt","plain","utf-8")
_email.attach(_part)
print _email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment