Commits

Ajay Roopakalu committed 7ad1211

Added faster patches instead of full updates on API calls and fixed some ID errors.

  • Participants
  • Parent commits 82635b8

Comments (0)

Files changed (1)

 IDToTitle = {}
 TaskNames = []
 UNCHANGED = 0
-UPDATED = 1
+TOGGLED = 1
 DELETED = 2
 bold = lambda x : '\x1b[1m' + x + '\x1b[0m'
 strike = lambda x : '\x1b[9m' + x + '\x1b[0m'
     # Also delete all children of deleted tasks
     for taskID in TaskLists[listID]:
         t = TaskLists[listID][taskID]
-        if 'parent' in t and TaskLists[listID][t['parent']]['modified'] is DELETED:
+        if 'parent' in t and t['parent'] in TaskLists[listID] and \
+            TaskLists[listID][t['parent']]['modified'] is DELETED:
             t['modified'] = DELETED
             if t['id'] in IDToTitle:
                 del IDToTitle[t['id']]
         return
 
     # toggle_task the given task
-    task['modified'] = UPDATED
+    task['modified'] = TOGGLED
     if task['status'] == 'needsAction':
         task['status'] = 'completed'
     else:
             if t['status'] == 'needsAction' and 'completed' in t:
                 del t['completed']
             prevs.append(t['id'])
-            t['modified'] = UPDATED
+            t['modified'] = TOGGLED
             TaskLists[listID][t['id']] = t
 
 def get_data():
     global TaskLists
-    
+
     # Only retrieve data once per run
     if TaskLists != {}:
         return 
         return
 
     # Over all task lists
-    for tasklist in tasklists['items']:
+    for tasklist in tasklists['items'][0:1]:
+        # Handle repeats
+        if tasklist['title'] in IDToTitle:
+            continue
         IDToTitle[tasklist['id']] = tasklist['title']
         TaskLists[tasklist['id']] = OrderedDict()
         tasks = service.tasks().list(tasklist = tasklist['id']).execute()
             task = TaskLists[tasklistID][taskID]
             if task['modified'] is UNCHANGED:
                 continue
-            elif task['modified'] is UPDATED:
-                service.tasks().update(tasklist = tasklistID, task = taskID, body = task).execute()
+            elif task['modified'] is TOGGLED:
+                service.tasks().patch(tasklist = tasklistID, task = taskID, 
+                                      body = {'status': task['status']}).execute()
             elif task['modified'] is DELETED:
                 service.tasks().delete(tasklist = tasklistID, task = taskID).execute()