def lists(order='display', task_counts=False): req = api.get('lists') lists = req.json() if order == 'display': positions = list_positions() def position(list): if list['list_type'] in SMART_LISTS: return SMART_LISTS.index(list['list_type']) elif list['id'] in positions: return positions.index(list['id']) + len(SMART_LISTS) else: return list['id'] lists.sort(key=position) if task_counts: for list in lists: update_list_with_tasks_count(list) for (index, list) in enumerate(lists): if list['list_type'] in SMART_LISTS: # List is not capitalized list['title'] = list['title'].title() list['order'] = index return lists
def list(id, task_counts=False): req = api.get('lists/' + id) info = req.json() # TODO: run this request in parallel if task_counts: update_list_with_tasks_count(info) return info
def reminders(list_id=None, task_id=None, completed=False): data = {'completed': completed} if list_id: data['list_id'] = int(list_id) elif task_id: data['task_id'] = int(task_id) req = api.get('reminders', data) reminders = req.json() return reminders
def reminders(list_id=None, task_id=None, completed=False): data = { 'completed': completed } if list_id: data['list_id'] = int(list_id) elif task_id: data['task_id'] = int(task_id) req = api.get('reminders', data) reminders = req.json() return reminders
def tasks(list_id, completed=False, subtasks=False, positions=None): start = time.time() req = api.get(('subtasks' if subtasks else 'tasks'), { 'list_id': int(list_id), 'completed': completed }) tasks = [] positions = [] task_type = '' if completed: task_type += 'completed ' if subtasks: task_type += 'sub' tasks = req.json() log.info('Retrieved %stasks for list %d in %s', task_type, list_id, time.time() - start) return tasks
def lists(order='display', task_counts=False): start = time.time() req = api.get('lists') lists = [] positions = [] if order == 'display': with futures.ThreadPoolExecutor(max_workers=2) as executor: def get_tasks(): lists.extend(req.json()) def get_positions(): positions.extend(task_positions(list_id)) executor.submit(get_tasks) executor.submit(get_positions) def position(list): if list['list_type'] in SMART_LISTS: return SMART_LISTS.index(list['list_type']) elif list['id'] in positions: return positions.index(list['id']) + len(SMART_LISTS) else: return list['id'] log.info('Retrieved lists and positions in %s', time.time() - start) lists.sort(key=position) else: lists = req.json() log.info('Retrieved lists in %s', time.time() - start) if task_counts: for list in lists: update_list_with_tasks_count(list) for (index, list) in enumerate(lists): if list['list_type'] in SMART_LISTS: # List is not capitalized list[u'title'] = list['title'].title() list[u'order'] = index return lists
def list_tasks_count(id): req = api.get('lists/tasks_count', {'list_id': id}) info = req.json() return info
def root(): req = api.get('root') info = req.json() return info
def list_positions(): req = api.get('list_positions') info = req.json() return info[0]['values']
def user(): req = api.get('user') user = req.json() return user
def task(id): req = api.get('tasks/%d' % int(id)) info = req.json() return info
def reminder(id): req = api.get('reminders/' + id) info = req.json() return info
def settings(): req = api.get('settings') settings = req.json() return settings