Update inkycal_todoist.py
This commit is contained in:
		| @@ -10,7 +10,7 @@ from inkycal.modules.template import inkycal_module | |||||||
| from inkycal.custom import * | from inkycal.custom import * | ||||||
|  |  | ||||||
| try: | try: | ||||||
|   import todoist |   from todoist_api_python.api import TodoistAPI | ||||||
| except ImportError: | except ImportError: | ||||||
|   print('todoist is not installed! Please install with:') |   print('todoist is not installed! Please install with:') | ||||||
|   print('pip3 install todoist-python') |   print('pip3 install todoist-python') | ||||||
| @@ -59,8 +59,7 @@ class Todoist(inkycal_module): | |||||||
|     else: |     else: | ||||||
|       self.project_filter = config['project_filter'] |       self.project_filter = config['project_filter'] | ||||||
|  |  | ||||||
|     self._api = todoist.TodoistAPI(config['api_key']) |     self._api = TodoistAPI(config['api_key']) | ||||||
|     self._api.sync() |  | ||||||
|     |     | ||||||
|     # give an OK message |     # give an OK message | ||||||
|     print(f'{filename} loaded') |     print(f'{filename} loaded') | ||||||
| @@ -86,7 +85,6 @@ class Todoist(inkycal_module): | |||||||
|     # Check if internet is available |     # Check if internet is available | ||||||
|     if internet_available() == True: |     if internet_available() == True: | ||||||
|       logger.info('Connection test passed') |       logger.info('Connection test passed') | ||||||
|       self._api.sync() |  | ||||||
|     else: |     else: | ||||||
|       raise Exception('Network could not be reached :/') |       raise Exception('Network could not be reached :/') | ||||||
|  |  | ||||||
| @@ -104,8 +102,12 @@ class Todoist(inkycal_module): | |||||||
|       (0, spacing_top + _ * line_height ) for _ in range(max_lines)] |       (0, spacing_top + _ * line_height ) for _ in range(max_lines)] | ||||||
|  |  | ||||||
|     # Get all projects by name and id |     # Get all projects by name and id | ||||||
|     all_projects = {project['id']: project['name'] |  | ||||||
|                     for project in self._api.projects.all()} |     #all_projects = {project['id']: project['name'] | ||||||
|  |     #                for project in self._api.get_projects()} | ||||||
|  |     all_projects = {} | ||||||
|  |     for project in self._api.get_projects(): | ||||||
|  |       all_projects[project.id] = project.name | ||||||
|  |  | ||||||
|     logger.debug(f"all_projects: {all_projects}") |     logger.debug(f"all_projects: {all_projects}") | ||||||
|  |  | ||||||
| @@ -126,22 +128,22 @@ class Todoist(inkycal_module): | |||||||
|                         'double check spellings in project_filter or leave' |                         'double check spellings in project_filter or leave' | ||||||
|                         'empty') |                         'empty') | ||||||
|  |  | ||||||
|     # Create single-use generator to filter undone and non-deleted tasks |     tasks = (task for task in self._api.get_tasks() if | ||||||
|     tasks = (task.data for task in self._api.state['items'] if |                 task.is_completed == False) | ||||||
|                task['checked'] == 0 and task['is_deleted']==0) |  | ||||||
|  |  | ||||||
|     # Simplify the tasks for faster processing |     # Simplify the tasks for faster processing | ||||||
|     simplified = [ |     simplified = [ | ||||||
|       { |         { | ||||||
|         'name':task['content'], |         'name':task.content, | ||||||
|         'due':task['due']['string'] if task['due'] != None else "", |         'due':task.due.string if task.due != None else "", | ||||||
|         'priority':task['priority'], |         'priority':task.priority, | ||||||
|         'project':all_projects[ task['project_id' ] ] if task['project_id'] in all_projects else "deleted" |         'project':all_projects[ task.project_id ] if task.project_id in all_projects else "deleted" | ||||||
|       } |         } | ||||||
|       for task in tasks] |         for task in tasks] | ||||||
|  |  | ||||||
|     # remove groups that have been deleted  |     # remove groups that have been deleted  | ||||||
|     simplified = [task for task in simplified if task['project'] != "deleted"] |     # - not sure if this is needed anymore or exactly how to do it --dealyllama | ||||||
|  |     #simplified = [task for task in simplified if task.project != "deleted"] | ||||||
|  |  | ||||||
|     logger.debug(f'simplified: {simplified}') |     logger.debug(f'simplified: {simplified}') | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user