-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeUpdate.py
More file actions
55 lines (38 loc) · 1.66 KB
/
makeUpdate.py
File metadata and controls
55 lines (38 loc) · 1.66 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
from datetime import date, timedelta
import pandas as pd
from config import csv_path, myLog
from makeTable import makeTable
############################################################################
def makeUpdate() -> None:
# THIS SCRIPT UPDATES ALL TASKS
myLog("-[ TODO CONSOLE ]-")
myLog("__makeUpdate.py__".upper())
today = date.today()
df_todo = pd.read_csv(csv_path, header=None)
DATE_FORMAT = "%Y-%m-%d"
DATE_COL = 1
max_day = None
for row, _ in df_todo.iterrows():
task_date = date.fromisoformat(df_todo.at[row, DATE_COL])
days_between = (task_date - today).days
# filters out tasks not overdue
if days_between > -1:
continue
if max_day is None:
max_day = abs(days_between)
new_duedate = today + timedelta(days=(days_between + max_day))
df_todo.at[row, DATE_COL] = new_duedate
saveCSV(df_todo, DATE_COL, DATE_FORMAT)
makeTable()
############################################################################
############################################################################
############################################################################
def saveCSV(df_list: pd.DataFrame, date_column: int, date_format: str) -> None:
myLog("method: saveCSV")
df_list[date_column] = pd.to_datetime(df_list[date_column], format=date_format)
df_list = df_list.sort_values(by=date_column)
df_list = df_list.reset_index(drop=True)
df_list.to_csv(csv_path, index=False, header=False, date_format=date_format)
############################################################################
if __name__ == "__main__":
makeUpdate()