Commits

Anonymous committed 5804647

Notes handling

  • Participants
  • Parent commits bc2d7de
  • Tags 0.1.0

Comments (0)

Files changed (2)

File src/mekk/rtmimport/nozbe_import.py

 # -*- coding: utf-8 -*-
 
 import re
+from collections import defaultdict
 
 # Mapping nozbe codes to rtm codes
 RECUR_2_MILK = {
     '7' : u"Every year",
     }
 
-re_badchars = re.compile(u"[^-\w]", re.UNICODE)
+# Name used for "preserve notes" task
+NOTE_TASK_NAME = u"Save this note"
+
+re_badchars = re.compile(u"[^-\w]+", re.UNICODE)
 def context_to_tag(ctx_name):
     name = re_badchars.sub("-",ctx_name)
     return u"@" + name
 #print context_to_tag(u"Komp/Platon")
 
 
-def import_nozbe_actions(rtm_updater, actions, verbose, dry_run):
+def import_nozbe_actions(rtm_updater, actions, notes, verbose, dry_run):
 
     for action in actions:
         name = action['name']
                 completed = completed)
            # priority, url, notes - unused
     
+    # First group notes by project
+    project_notes = defaultdict(lambda: [])
+    for note in notes:
+        project_notes[note['project_name']].append(
+            (note['name'], note['body'])
+            )
+
+    # ... and save them
+    for project_name, here_notes in project_notes.iteritems():
+        if dry_run or (project_name == "Inbox"):
+            list_id = None
+        else:
+            list_id = rtm_updater.find_or_create_list(project_name)
+        task_name = NOTE_TASK_NAME
+        if verbose:
+            print "Creating preserve note task on list %(project_name)s. Task name: %(task_name)s\n" % locals()
+            print "Notes bound:\n"
+            for (title, body) in here_notes:
+                print title, "\n"
+                print "   ", body.replace("\n", "\n    "), "\n"
+        if not dry_run:
+            rtm_updater.create_task(
+                name = NOTE_TASK_NAME,
+                list_id = list_id,
+                tags = ["Note"],
+                due_date = "today",
+                notes = here_notes)

File src/mekk/rtmimport/run.py

 
         from nozbe_import import import_nozbe_actions
 
-        import_nozbe_actions(updater, actions = data['actions'],
+        import_nozbe_actions(updater, actions = data['actions'], notes = data['notes'],
                              verbose = opts.verbose, dry_run = opts.dry_run)