Skip to content

Commit 336b348

Browse files
Save work. It works, kinda.
1 parent 4fac240 commit 336b348

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

source/main.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import configparser
1616

1717
from datetime import datetime
18-
#from dateutil import parser
18+
from dateutil import parser
1919
import re
2020

2121

@@ -269,7 +269,7 @@ def get_uniqs(matchDict,tod_tasks,hab_tasks):
269269

270270
for tod in tod_tasks:
271271
tid = tod.id
272-
if tod.is_completed:
272+
if tod.complete:
273273
if tid not in matchDict.keys():
274274
tod_uniq.append(tod)
275275

@@ -279,6 +279,21 @@ def get_uniqs(matchDict,tod_tasks,hab_tasks):
279279
hab_uniq.append(hab)
280280

281281
return tod_uniq, hab_uniq
282+
283+
def getNewTodoTasks(matchDict,tod_tasks,hab_tasks):
284+
tod_uniq = []
285+
hab_uniq = []
286+
287+
for todo in tod_tasks:
288+
tid = todo.id
289+
if tid not in matchDict.keys():
290+
tod_uniq.append(todo)
291+
for hab in hab_tasks:
292+
tid = hab.id
293+
if tid not in matchDict.keys():
294+
hab_uniq.append(hab)
295+
296+
return tod_uniq, hab_uniq
282297
'''
283298
def make_daily_from_tod(tod):
284299
import re
@@ -346,7 +361,7 @@ def make_daily_from_tod(tod):
346361
347362
finished_hab = HabTask(new_hab)
348363
return finished_hab
349-
364+
'''
350365
def make_hab_from_tod(tod_task):
351366
new_hab = {'type':'todo'}
352367
new_hab['text'] = tod_task.name
@@ -369,6 +384,7 @@ def make_hab_from_tod(tod_task):
369384
finished = HabTask(new_hab)
370385
return finished
371386

387+
'''
372388
def make_tod_from_hab(hab):
373389
project_id = tod_projects[0].data['id']
374390
tod = {}

source/oneWaySync.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import random
1717
import json
1818
#from hab_task import HabTask
19-
#from todo_task import TodTask
19+
from todo_task import TodTask
2020
from datetime import datetime
2121
from datetime import timedelta
2222
# from dateutil import parser
@@ -46,7 +46,11 @@ def get_tasks(token):
4646
todoToken = config.getTodoistToken('auth.cfg')
4747

4848
#Okay, now I need a list of todoist tasks.
49-
todoTasks, todoApi = get_tasks(todoToken)
49+
todoist_tasks, todoApi = get_tasks(todoToken) # todoist_tasks used to be tod_tasks
50+
51+
tod_tasks = []
52+
for i in range(0, len(todoist_tasks)):
53+
tod_tasks.append(TodTask(todoist_tasks[i]))
5054

5155
# date stuff
5256
today = datetime.now()
@@ -55,38 +59,26 @@ def get_tasks(token):
5559
yesterday = datetime.now() - one_day
5660
yesterday_str = yesterday.strftime("%Y-%m-%d")
5761

58-
overdue_tasks = [] # overdue_tasks used to be tod_tasklist
59-
todoist_tasks = [] # todoist_tasks used to be tod_tasks
60-
other_tasks = []
61-
for task in todoTasks:
62-
if task.due != None and not task.is_completed:
63-
# filter by due date
64-
if task.due.datetime == None and task.due.date != None:
65-
dateStr = task.due.date
66-
if dateStr == today_str:
67-
todoist_tasks.append(task)
68-
overdue_tasks.append(task)
69-
elif dateStr == yesterday_str:
70-
overdue_tasks.append(task)
71-
else:
72-
other_tasks.append(task)
73-
7462
"""
7563
Okay, I want to write a little script that checks whether or not a task is there or not and, if not, ports it.
7664
"""
7765
matchDict = main.openMatchDict()
7866

7967
#Also, update lists of tasks with matchDict file...
80-
matchDict = main.update_tod_matchDict(todoist_tasks, matchDict)
68+
matchDict = main.update_tod_matchDict(tod_tasks, matchDict)
8169
matchDict = main.update_hab_matchDict(hab_tasks, matchDict)
8270

8371
#We'll want to just... pull all the unmatched completed tasks out of our lists of tasks. Yeah?
84-
tod_uniq, hab_uniq = main.get_uniqs(matchDict, todoist_tasks, hab_tasks)
72+
tod_uniq, hab_uniq = main.get_uniqs(matchDict, tod_tasks, hab_tasks)
8573

8674
#Okay, so what if there are two matched tasks in the two uniq lists that really should be paired?
8775
matchDict = main.check_newMatches(matchDict,tod_uniq,hab_uniq)
8876

8977
#Here anything new in todoist gets added to habitica
78+
tod_uniq = []
79+
hab_uniq = []
80+
tod_uniq, hab_uniq = main.getNewTodoTasks(matchDict, tod_tasks, hab_tasks)
81+
9082
for tod in tod_uniq:
9183
tid = tod.id
9284
if tod.recurring == "Yes":

source/todo_task.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@
2020
"""
2121

2222
class TodTask(object):
23-
def __init__(self, task_dict=None):
23+
def __init__(self, task=None):
2424
""" Initialise the task.
2525
2626
Args:
2727
task_dict (dict): the Todoist task dictionary, as released by task_all.
2828
"""
2929
super().__init__()
3030

31-
if not task_dict:
31+
if not task:
3232
task_dict = {'text': 'scriptabit todo'}
3333

34+
task_dict = task.to_dict()
35+
3436
if not isinstance(task_dict, dict):
3537
raise TypeError(type(task_dict))
3638

@@ -104,7 +106,7 @@ def hardness(self):
104106
@property
105107
#is task complete? 0 for no, 1 for yes
106108
def complete(self):
107-
return self.__task_dict['checked']
109+
return self.__task_dict['is_completed']
108110

109111
@complete.setter
110112
def complete(self, status):

0 commit comments

Comments
 (0)