Skip to content

Instantly share code, notes, and snippets.

@ngoffee
Created October 27, 2012 16:19
Show Gist options
  • Save ngoffee/3965224 to your computer and use it in GitHub Desktop.
Save ngoffee/3965224 to your computer and use it in GitHub Desktop.
Convert Remember the Milk tasks to Evernote notes
#!/usr/bin/env python
# rtm2evernote.py
#
# Convert Remember the Milk tasks to Evernote notes, using approximately
# the the Evernote setup recommended in "The Secret Weapon":
#
# http://www.thesecretweapon.org/the-secret-weapon-manifesto/setting-up-the-secret-weapon
#
# requires Python >= 2.7 (for ElementTree.iter())
#
# Also requires Geeknote: http://www.geeknote.me/
# Install/untar Geeknote and set _GEEKNOTE below to point to the executable
#
# Find your RTM Atom feed here:
# https://www.rememberthemilk.com/atom/<username>
#
# Assumes you organize your RTM todos by tags, not by lists (should be
# easily modifiable to do the latter). Maps things to Evernote as
# follows:
#
# * <first tag> :<first tag>:
# ** TODO [<priority] Item 1
# ** TODO Item 2 :<othertags>:
# ** TODO Item 3
# <note title>
# <note content>
from collections import defaultdict
from subprocess import check_call
import os.path
import sys
import xml.etree.ElementTree as etree
_atom_ns = 'http://www.w3.org/2005/Atom'
_xhtml_ns = 'http://www.w3.org/1999/xhtml'
_priority_map = {'none': None, '1': '1-Now', '2': '2-Next', '3': '3-Soon'}
# path to geeknote executable
# must be modified to allow empty content
_GEEKNOTE = 'geeknote'
def _rtm2evernote(input_file):
tree = etree.parse(input_file)
for entry in tree.iter('{%s}entry' % _atom_ns):
title = entry.find('{%s}title' % _atom_ns).text
notebook = 'INBOX'
tags = []
for span in entry.iter('{%s}span' % _xhtml_ns):
if span.get('class') == 'rtm_tags_value':
if span.text == 'none':
tags.append('UNTAGGED')
else:
tags.extend(x.strip() for x in span.text.split(','))
elif span.get('class') == 'rtm_priority_value':
priority = _priority_map.get(span.text, '!%s' % span.text)
if priority:
tags.append(priority)
for div in entry.iter('{%s}div' % _xhtml_ns):
if (div.get('class') in ('rtm_note_title_container',
'rtm_note_content')
and '!HAD_NOTE' not in tags):
tags.append('!HAD_NOTE')
cmd = ['geeknote', 'create', '--notebook', 'RTM_IMPORT',
'--title', title, '--tags', ','.join(tags)]
print ' '.join(cmd)
check_call(cmd)
def main():
args = sys.argv[1:]
if len(args) != 1:
print >> sys.stderr, \
"usage: %s <file>" % os.path.basename(sys.argv[0])
sys.exit(1)
_rtm2evernote(args[0])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment