-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeTasks.py
More file actions
255 lines (204 loc) · 9.1 KB
/
makeTasks.py
File metadata and controls
255 lines (204 loc) · 9.1 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/Users/diegoibarra/.config/pyenv/versions/3.13.0/envs/ToDo/bin/python
from datetime import datetime, timedelta
from sys import argv
import pandas as pd
from pandas import DataFrame
from config import copy2Clipboard, csv_path, getDialog, log, myLog
from makeTable import makeTable
############################################################################
def makeTasks(arg: list) -> None:
# ENTRY POINT FROM INPUT-CONSOLE
# THIS SCRIPT ADDS/REMOVES TASKS
myLog("-[ TODO CONSOLE ]-")
myLog("__makeTasks.py__".upper())
todos_list = pd.read_csv(csv_path, header=None)
if len(arg) == 0:
myLog("NO ITEMS PROVIDED")
saveCSV(todos_list)
elif arg[0] == "toggle":
makeTable(arg[0])
return 0
else:
logAllTasks(arg)
for _index, _item in enumerate(arg):
myLog(f"Item {_index + 1}: {_item.upper()}")
if "-" in _item:
task_info = _item.split(" - ")
if task_info[0].isdigit():
task_info[0] = todos_list.iloc[int(task_info[0])-1, 0]
if "i" in task_info:
taskImportance(task_info)
continue
if "r" in task_info:
taskRename(task_info)
continue
duedate_value = (task_info[1].strip()).lower()
if duedate_value != "done":
taskAddEdit(task_info)
elif duedate_value == "done":
taskComplete(task_info)
else:
myLog(f"UNKNOWN INPUT: {_item}", log.ERROR)
makeTable()
############################################################################
############################################################################
############################################################################
def logAllTasks(task_list: list) -> None:
"""
Logs all tasks at the beginning of the log message
Args:
task_list: (list): raw task info
"""
for _count, _item in enumerate(task_list):
myLog(f"{' ' * 3}ITEM {_count+1}: {_item.upper()}")
############################################################################
def taskImportance(assignment_info: list[str]) -> None:
myLog("method: taskImportance")
df_todo: DataFrame = pd.read_csv(csv_path, header=None)
all_assignments_count = len(df_todo.index)
# USING AN INTEGER TO EDIT A TASK
for _index in range(all_assignments_count):
task_label = df_todo.loc[_index, ASSIGNMENT_COL].lower()
if task_label == assignment_info[0].lower():
if task_label[-1] == "!":
myLog("method: taskImportance - NOT IMPORTANT")
task_label = task_label[:-1]
else:
task_label = f"{task_label}!"
myLog("method: taskImportance - IMPORTANT")
myLog("method: taskImportance -- IMPORTANT TASK")
df_todo.loc[_index, ASSIGNMENT_COL] = task_label
saveCSV(df_todo)
break
############################################################################
def taskRename(assignment_info: list[str]) -> None:
myLog("method: taskRename")
df_todo = pd.read_csv(csv_path, header=None)
all_assignments_count = len(df_todo.index)
# USING AN INTEGER TO EDIT A TASK
if assignment_info[0].isdigit():
myLog("INTEGERINTEGER-SHOULDNOLONGERRUN - method: taskRename -- RENAME TASK")
task_label = df_todo.loc[(int(assignment_info[0]) - 1), ASSIGNMENT_COL]
df_todo.loc[(int(assignment_info[0]) - 1), ASSIGNMENT_COL] = assignment_info[ASSIGNMENT_NEW_NAME]
saveCSV(df_todo)
return
for _index in range(all_assignments_count):
task_label = df_todo.loc[_index, ASSIGNMENT_COL].lower()
if task_label == assignment_info[0].lower():
myLog("method: taskRename -- RENAME TASK")
df_todo.loc[_index, ASSIGNMENT_COL] = assignment_info[ASSIGNMENT_NEW_NAME]
saveCSV(df_todo)
break
############################################################################
def taskAddEdit(assignment_info: list[str]) -> None:
myLog("method: taskAddEdit")
def invalidInput(item_info: list[str]) -> None:
"""
If input is invalid, returns '05/25/1996' datetime.
That datetime will act as an 'Invalid Input' and will skip the current input
"""
item_string = " - ".join(item_info)
copy2Clipboard(item_string)
getDialog(f"{str(item_string)}\nis invalid\n\nItem Copied to Clipboard")
myLog(f"{str(item_string)} NOT VALID")
return datetime(year=1996, month=5, day=25)
############################################################################
def getFullDate(item_info: list[str]) -> datetime:
myLog("method: getFullDate")
today_date = datetime.today().replace(minute=0, second=0, microsecond=0)
today_str = str(today_date.day)
if len(today_str) < 2:
today_str = "0" + today_str
today_month = str(today_date.month)
today_compare = int(today_month + today_str)
if item_info[1].isalpha():
if item_info[1].lower() in ("today", "t"):
return today_date
if item_info[1].lower() == "tomorrow":
return today_date + timedelta(days=1)
return invalidInput(item_info)
elif "/" in item_info[1]:
item_index = str(item_info[1]).split("/")
item_day = item_index[1]
if len(item_day) < 2:
item_day = f"0{item_day}"
item_month = item_index[0]
item_compare = int(f"{item_month}{item_day}")
if today_compare <= item_compare:
item_year = today_date.year
elif today_compare > item_compare:
item_year = today_date.year + 1
return datetime(int(item_year), int(item_month), int(item_day))
else:
return invalidInput(item_info)
############################################################################
df_todo = pd.read_csv(csv_path, header=None)
all_assignments_count = len(df_todo.index)
item_date = getFullDate(assignment_info).strftime(DATE_FORMAT)
if item_date == "1996-05-25":
return
# USING AN INTEGER TO EDIT A TASK
if assignment_info[0].isdigit():
myLog("INTEGERINTEGER-SHOULDNOLONGERRUN - method: taskAddEdit -- EDIT TASK")
task_label = df_todo.loc[(int(assignment_info[0]) - 1), ASSIGNMENT_COL]
df_todo.loc[(int(assignment_info[0]) - 1), DATE_COL] = item_date
saveCSV(df_todo)
return
for _index in range(all_assignments_count):
task_label = df_todo.loc[_index, ASSIGNMENT_COL].lower()
if task_label == assignment_info[0].lower():
myLog("method: taskAddEdit -- EDIT TASK")
df_todo.loc[_index, DATE_COL] = item_date
saveCSV(df_todo)
break
elif _index == (all_assignments_count - 1):
myLog("method: taskAddEdit -- ADD TASK")
new_task = pd.DataFrame([[assignment_info[0], item_date]], columns=df_todo.columns)
df_todo = pd.concat([new_task, df_todo], ignore_index=True)
saveCSV(df_todo)
break
############################################################################
def taskComplete(assignment_info: list) -> None:
myLog("method: taskComplete -- REMOVE TASK")
df_todo = pd.read_csv(csv_path, header=None)
all_assignments_count = len(df_todo.index)
try:
assignment_info[0] = int(assignment_info[0])
except ValueError:
pass
if isinstance(assignment_info[0], int):
task_label = df_todo.loc[(assignment_info[0] - 1), ASSIGNMENT_COL]
df_todo.drop(assignment_info[0] - 1, inplace=True)
saveCSV(df_todo)
return
for _index in range(all_assignments_count):
task_label = df_todo.loc[_index, ASSIGNMENT_COL].lower()
if task_label == assignment_info[0].lower():
df_todo.drop(_index, inplace=True)
saveCSV(df_todo)
break
############################################################################
def sortTasks(df_list):
df_list[DATE_COL] = pd.to_datetime(df_list[DATE_COL], format=DATE_FORMAT)
df_list = df_list.sort_values(by=DATE_COL).reset_index(drop=True)
_location = 0
for _idx, _row in df_list.iterrows():
if "!" in _row[ASSIGNMENT_COL]:
row_obj = df_list.loc[[_idx]]
df_list = df_list.drop(df_list.index[_idx])
df_top = df_list.iloc[:_location]
df_bottom = df_list.iloc[_location:]
df_list = pd.concat([df_top, row_obj, df_bottom])
_location += 1
return df_list
def saveCSV(df_list) -> None:
myLog("method: saveCSV")
sorted_df = sortTasks(df_list).reset_index(drop=True)
sorted_df.to_csv(csv_path, index=False, header=False, date_format=DATE_FORMAT)
############################################################################
if __name__ == "__main__":
ASSIGNMENT_COL = 0
DATE_COL = 1
ASSIGNMENT_NEW_NAME = 2
DATE_FORMAT = "%Y-%m-%d"
makeTasks(argv[1:])