-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeTable.py
More file actions
executable file
·199 lines (167 loc) · 8.26 KB
/
makeTable.py
File metadata and controls
executable file
·199 lines (167 loc) · 8.26 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
#!/Users/diegoibarra/.config/pyenv/versions/3.13.0/envs/ToDo/bin/python
# required env for launchdaemon execution
from datetime import datetime, timedelta
from os import listdir, path
from subprocess import run
from sys import argv
import dataframe_image as dfi
import pandas as pd
from pandas import DataFrame
from config import clearScreen, csv_path, day_limit, log, myLog, path_dict, tableStyle
from makeWallpaper import makeWallpaper
############################################################################
#region MAKETABLE
def makeTable(_from="") -> None:
# ENTRY POINT FOR LAUNCHDAEMON
# CALLING THIS SCRIPT FROM LAUNCH DAEMON ALLOWS FOR TABLE TO BE UPDATED
clearScreen()
myLog("__makeTable.py__".upper())
make_image: bool = True
images_directory = path_dict["images"]
table_exists = deletePreviousTable(images_directory)
if _from == "toggle":
myLog("toggle argument")
if table_exists:
make_image = False
myLog("TURN DESKTOP OFF")
HEADER = ["TASKS", "DUE DATE", "DAYS", "_Days"]
TASK_COL = HEADER[0]
DATE_COL = HEADER[1]
DAYS_COL = HEADER[3]
DAY_STR_COL = HEADER[2]
DATE_FORMAT = "%Y-%m-%d"
dt_day_limit = timedelta(days=day_limit)
time_now = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
df_todo = pd.read_csv(csv_path, header=None)
df_todo.rename(columns={0: HEADER[0], 1: HEADER[1]}, inplace=True)
df_todo[DATE_COL] = pd.to_datetime(df_todo[DATE_COL], format=DATE_FORMAT)
df_todo[DAY_STR_COL] = ""
df_todo[DAYS_COL] = df_todo[DATE_COL] - time_now
df_todo[DATE_COL] = df_todo[DATE_COL].dt.strftime("%m/%d")
df_soon: DataFrame = df_todo[(df_todo[DAYS_COL] < dt_day_limit) | (df_todo[TASK_COL].str.endswith("!"))]
if not df_soon.empty:
for index, row in df_soon.iterrows():
days_left = row[DAYS_COL].days
if days_left == 0:
df_soon.loc[index, TASK_COL] = row[TASK_COL].upper()
df_soon.loc[index, DAY_STR_COL] = "TODAY!"
elif days_left == -1:
df_soon.loc[index, TASK_COL] = row[TASK_COL].upper()
df_soon.loc[index, DAY_STR_COL] = "YESTERDAY!"
elif days_left < -1:
df_soon.loc[index, TASK_COL] = row[TASK_COL].upper()
df_soon.loc[index, DAY_STR_COL] = f"{days_left} DAYS AGO!"
elif days_left == 1:
df_soon.loc[index, DAY_STR_COL] = "Tomorrow"
elif days_left > 1:
df_soon.loc[index, DAY_STR_COL] = f"{days_left} Days"
df_styled = df_soon.style.set_table_styles(styleTable(df_soon, HEADER)).hide()
try:
if make_image:
myLog("TURN DESKTOP ON")
dfi.export(df_styled, path.join(images_directory, "table.png"), dpi=300)
except Exception:
myLog("DataFrame_Image Module Error", log.ERROR)
makeWallpaper()
###########################################################################
###########################################################################
###########################################################################
def deletePreviousTable(images_directory: str) -> bool:
myLog("method: deletePreviousTable")
previous_table = [x for x in listdir(images_directory) if x.startswith("table")]
if len(previous_table) == 0:
myLog("TABLE DOES NOT EXIST")
return False
previous_path = path.join(images_directory, previous_table[0])
run(["rm", "-f", previous_path])
myLog("TABLE DOES EXIST")
return True
###########################################################################
def styleTable(df: pd.DataFrame, headerCol: list) -> list:
myLog("method: styleTable")
cStyle = tableStyle()
border_width = cStyle["border_width"]
box_color = cStyle["box_color"]
head_font = cStyle["head_font"]
header_line_color = cStyle["header_line_color"]
head_fontsize = cStyle["head_font_size"]
body_font = cStyle["body_font"]
body_fontsize = cStyle["body_font_size"]
head_font_color = cStyle["head_font_color"]
body_font_color = cStyle["body_font_color"]
rECo = cStyle["rowCoE"]
rOCo = cStyle["rowCoO"]
paddingHead = f"padding-top: {0}em; padding-bottom: {0}em;" # % (0, 0)
propsHead = f"font-weight:bold; background-color:#{box_color}; font-family: {head_font}; color: #{head_font_color}; font-size: {head_fontsize}em;"
paddingBody = f"padding-top: {0.4}em; padding-bottom: {0.4}em;"
# paddingBody = f"padding-top: {0.3}em; padding-bottom: {0.3}em;"
# paddingBodyL = f"padding-left: {0.5}em;"
paddingBodyL = f"padding-left: {0.5}em; padding-top: {0.4}em; padding-bottom: {0.4}em;"
propsBodyE = f"font-weight:normal; background-color: #{rECo}; font-family: {body_font}; color: #{body_font_color}; font-size: {body_fontsize}em;"
propsBodyO = f"font-weight:normal; background-color: #{rOCo}; font-family: {body_font}; color: #{body_font_color}; font-size: {body_fontsize}em;"
bhBottom = f"border-bottom: {border_width - 2}px solid #{header_line_color};"
bTop = f"border-top: {border_width}px solid #{box_color};"
bRight = f"border-right: {border_width}px solid #{box_color};"
bBottom = f"border-bottom: {border_width}px solid #{box_color};"
bLeft = f"border-left: {border_width}px solid #{box_color};"
styleList = [
# COLOR
{"selector": "th.col_heading", "props": f"{propsHead}; {paddingHead}; {bTop}; {bhBottom};"},
{"selector": "tbody tr:nth-child(even)", "props": f"{propsBodyE};"},
{"selector": "tbody tr:nth-child(odd)", "props": f"{propsBodyO};"},
# ALIGNMENT
{"selector": "th.col0", "props": f"text-align: left;{bLeft}; {paddingBodyL}; min-width: 450px;"},
{"selector": "td.col0", "props": f"text-align: left; {paddingBodyL}; {bLeft};"},
{"selector": "th.col1", "props": "text-align: center;"},
{"selector": "td.col1", "props": f"text-align: center; {paddingBody}"},
{"selector": "th.col2", "props": f"text-align: center; {bRight}"},
{"selector": "td.col2", "props": f"text-align: right; {paddingBody}; {bRight}"},
{"selector": "td.col3", "props": "display: none"},
{"selector": "th.col3", "props": "display: none"},
{"selector": "tbody tr:nth-last-child(1)", "props": f"{paddingBody}"},
{"selector": "tbody tr:nth-last-child(1)", "props": f"text-align: right; {paddingBody}; {bBottom}"},
]
# today_length = len(df[df[headerCol[2]].str.contains("!")])
# important_length = len(df[df[headerCol[0]].str.contains("!")])
# priority_length = max(today_length, important_length)
count = 0
for index, row in df.iterrows():
tempToday = {}
dict_keys = ["selector", "props"]
tempToday[dict_keys[0]] = ""
# Priority Tasks
if "!" in row["TASKS"]:
tempToday[dict_keys[1]] = "\
text-decoration: underline solid 0.15em #%s; \
font-weight: bold; \
color: #%s;" % (cStyle["priorityCo"], cStyle["priorityCo"])
elif "!" in row["DAYS"]:
tempToday[dict_keys[1]] = "font-weight: bold; color: #%s;" % (cStyle["pastCo"])
else:
break
tempToday["selector"] = f"tbody tr:nth-child({count + 1})"
count += 1
styleList.append(tempToday)
del tempToday
# if priority_length > 0:
# for i in range(priority_length):
# tempToday = {}
# dict_keys = ["selector", "props"]
# tempToday[dict_keys[0]] = ""
# if important_length != 0:
# tempToday[dict_keys[1]] = "\
# text-decoration: underline solid 0.15em #%s; \
# font-weight: bold; \
# color: #%s;" % (cStyle["priorityCo"], cStyle["priorityCo"])
# important_length -= 1
# else:
# tempToday[dict_keys[1]] = "font-weight: bold; color: #%s;" % (cStyle["pastCo"])
# tempToday["selector"] = f"tbody tr:nth-child({i + 1})"
# styleList.append(tempToday)
# del tempToday
return styleList
###########################################################################
if __name__ == "__main__":
if len(argv) == 1:
argv.append("vscode")
makeTable(argv[1])