Skip to content

Commit 142436a

Browse files
Clean-up another warning.
1 parent 27da6d8 commit 142436a

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

source/oneWaySync.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,24 @@
1111
import pickle
1212
import time
1313

14-
from todoist_api_python.api import TodoistAPI
15-
from todoist_api_python.endpoints import get_sync_url
16-
from todoist_api_python.http_requests import get
17-
from todoist_api_python.models import Task
14+
1815
import main
1916
from todo_task import TodTask
17+
from todo_api_plus import TodoAPIPlus
2018
import config
2119
import habitica
2220

2321

2422
def get_tasks(token):
2523
tasks = []
26-
api = TodoistAPI(token)
24+
api = TodoAPIPlus(token)
2725
try:
2826
tasks = api.get_tasks()
2927
except Exception as error:
3028
print(error)
3129
return tasks, api
3230

3331

34-
def dict_to_task(obj, url):
35-
obj['comment_count'] = obj['note_count']
36-
obj['is_completed'] = (obj['completed_at'] != '')
37-
obj['created_at'] = "unknown"
38-
obj['creator_id'] = obj['user_id']
39-
obj['description'] = obj['content']
40-
obj["priority"] = ''
41-
obj['url'] = url
42-
return Task.from_dict(obj)
43-
44-
45-
def get_all_completed_items(api):
46-
url = get_sync_url('completed/get_all')
47-
completed_items = get(api._session, url, api._token)
48-
tasks = completed_items['items']
49-
return [dict_to_task(obj, url) for obj in tasks]
50-
51-
5232
def sync_todoist_to_habitica():
5333
# todayFilter = todo_api.filters.add('todayFilter', 'today')
5434

@@ -84,7 +64,7 @@ def sync_todoist_to_habitica():
8464
match_dict = main.update_hab_matchDict(hab_tasks, match_dict)
8565

8666
# We'll want to just... pull all the unmatched completed tasks out of our lists of tasks. Yeah?
87-
tod_done = [TodTask(task) for task in get_all_completed_items(todo_api)]
67+
tod_done = [TodTask(task) for task in todo_api.get_all_completed_items()]
8868
tod_uniq, hab_uniq = main.get_uniqs(match_dict, tod_done, hab_tasks)
8969

9070
# Okay, so what if there are two matched tasks in the two uniq lists that really should be paired?

source/todo_api_plus.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Module for todo api plus"""
2+
from todoist_api_python.api import TodoistAPI
3+
from todoist_api_python.endpoints import get_sync_url
4+
from todoist_api_python.http_requests import get
5+
from todoist_api_python.models import Task
6+
import requests
7+
8+
9+
def dict_to_task(obj, url):
10+
'''Helper function to convert dict to Task class'''
11+
obj['comment_count'] = obj['note_count']
12+
obj['is_completed'] = obj['completed_at'] != ''
13+
obj['created_at'] = "unknown"
14+
obj['creator_id'] = obj['user_id']
15+
obj['description'] = obj['content']
16+
obj["priority"] = ''
17+
obj['url'] = url
18+
return Task.from_dict(obj)
19+
20+
21+
class TodoAPIPlus(TodoistAPI):
22+
"""Extend TodoistAPI class"""
23+
def __init__(self, token: str, session: requests.Session | None = None) -> None:
24+
TodoistAPI.__init__(self, token, session)
25+
26+
def get_all_completed_items(self):
27+
'''Get all completed tasks from Todoist API'''
28+
url = get_sync_url('completed/get_all')
29+
completed_items = get(self._session, url, self._token)
30+
tasks = completed_items['items']
31+
return [dict_to_task(obj, url) for obj in tasks]

0 commit comments

Comments
 (0)