forked from jenmei/Habitica-todo
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtodo_task.py
More file actions
188 lines (157 loc) · 4.74 KB
/
todo_task.py
File metadata and controls
188 lines (157 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# -*- coding: utf-8 -*-
""" Implements a Todoist synchronisation task.
"""
# Ensure backwards compatibility with Python 2
from __future__ import (
absolute_import,
division,
print_function,
unicode_literals)
from builtins import *
from datetime import datetime
from tzlocal import get_localzone
import pytz
#from .dates import parse_date_utc
#from .task import CharacterAttribute, ChecklistItem, Difficulty, Task
"""
So what if I did todoist work a sliiiightly different way, using all my task IDs?
"""
class TodTask(object):
def __init__(self, task=None):
""" Initialise the task.
Args:
task_dict (dict): the Todoist task dictionary, as released by task_all.
"""
super().__init__()
if not task:
task_dict = {'text': 'scriptabit todo'}
task_dict = task.to_dict()
if not isinstance(task_dict, dict):
raise TypeError(type(task_dict))
self.__task_dict = task_dict
tzone = pytz.timezone(str(get_localzone()))
self.__task_dict['due']['date'] = self.due.astimezone(tzone)
@property
#Get the task dictionary as is
def task_dict(self):
return self.__task_dict
@property
#Is this task recurring?
def recurring(self):
if self.__task_dict.get('date_string', None) == None:
return 'No'
elif 'ev' in self.__task_dict['date_string']:
return 'Yes'
else:
return 'No'
@property
#Get the task dictionary as is
def recurring_type(self):
if reg in self.__task_dict['date_string']:
return 'daily'
else:
return 'weekly'
@property
#Get task ID
def id(self):
return self.__task_dict['id']
@property
#task name
def history(self):
import main
tod_user = main.tod_login('auth.cfg')
activity = tod_user.activity.get(object_type='item', object_id = self.__task_dict['id'], event_type='completed')
return activity
@property
#task name
def name(self):
return self.__task_dict['content']
@property
#date task was added to todoist
def date_added(self):
return self.__task_dict['date_added']
@property
#priority of task
def priority(self):
return self.__task_dict['priority']
@property
#difficulty: priority of task rendered to be compatible with habtask
def hardness(self):
diffID = self.__task_dict['priority']
if diffID == 4:
return "A"
elif diffID == 3:
return "B"
elif diffID == 2:
return "C"
else:
return "C"
@property
#is task complete? 0 for no, 1 for yes
def is_completed(self):
return self.__task_dict['is_completed']
# TODO: No longer works
@is_completed.setter
def complete(self, status):
self.__task_dict['checked'] = status
@property
#due date
def due_date(self):
return self.__task_dict['due']
@due_date.setter
def due_date(self, date):
self.__task_dict['due'] = date
@property
#due date
def due(self):
from dateutil import parser
import datetime
if self.__task_dict['due'] is not None:
if isinstance(self.__task_dict['due'], dict):
date = parser.parse(self.__task_dict['due']['date'])
else:
date = self.__task_dict['due']
return date
return ''
@property
#is it due TODAY?
def dueToday(self):
from dateutil import parser
from datetime import datetime
from datetime import timedelta
import pytz
today = datetime.utcnow().replace(tzinfo=pytz.UTC)
try:
# that datetime thing is pulling todoist's due dates to my time zone
wobble = parser.parse(self.__task_dict['due']) - timedelta(hours=6)
dueDate = wobble.date()
except:
dueDate = ""
if today.date() >= dueDate:
return 'Yes'
elif dueDate == "":
return "No due date"
else:
return 'No'
@property
#date in string form
def date_string(self):
return self.__task_dict['date_string']
@property
#should it be due today?
def dueLater(self):
from dateutil import parser
import datetime
import pytz
today = datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)
try:
wobble = parser.parse(self.__task_dict['due'])
dueDate = wobble.date()
except:
dueDate = ""
if today.date() == dueDate:
return 'Yes'
elif dueDate == "":
return "No due date"
else:
return 'No'