]> apps.delaporte.us Git - dotfiles.git/blob - invoke/school/tasks.py
Do not try to symlink css file
[dotfiles.git] / invoke / school / tasks.py
1 from invoke import task
2 from pandas_ods_reader import read_ods
3 import pandas as pd
4 from weasyprint import HTML
5
6 from datetime import datetime as dt
7 from datetime import timedelta
8 import os
9
10 HOME = os.path.expanduser('~')
11 DATE_FORMAT = '%Y-%m-%d'
12 TODAY = dt.now().strftime(DATE_FORMAT)
13
14 SCHOOL_DIR = f'{HOME}/School/Assignments'
15 ARCHIVE = f'{SCHOOL_DIR}/archive'
16 ODS_FILE = f'{HOME}/School/Assignments/assignments.ods'
17 BIN = f'{HOME}/envs/invoke/bin'
18 STUDENTS = os.environ.get('STUDENTS').split('|')
19
20 def browse(c, url):
21 c.run(f"librewolf {url}", asynchronous=True)
22
23
24 def code(c, path):
25 c.run(f"codium {path}")
26
27
28 def folder(c, path):
29 # c.run(f'dolphin {path}', asynchronous=True)
30 c.run(f"nemo {path}", asynchronous=True)
31 # c.run(f'konsole --workdir {path}',asynchronous=True)
32
33
34 @task
35 def open_folder(c):
36 folder(c, SCHOOL_DIR)
37
38
39 @task
40 def dump_ods(c):
41 df = read_ods(ODS_FILE)
42 print(df)
43
44
45 @task
46 def print_week(c, person, monday):
47 print(f'# {person}\'s Assignements for Week of {monday}')
48
49 motd = open(f'{SCHOOL_DIR}/motd.txt', 'r').read()
50 print(motd)
51
52
53 day = dt.strptime(monday, DATE_FORMAT)
54 for i in range(0,5):
55 print_day(c, person, day.strftime(DATE_FORMAT))
56 day = day + timedelta(days=1)
57
58 @task
59 def md_week(c, person, monday):
60 c.run(f'cd {SCHOOL_DIR};{BIN}/invoke print-week {person} {monday} > {SCHOOL_DIR}/{person}.{monday}.md')
61
62
63 @task
64 def md_all(c, monday):
65 for person in STUDENTS:
66 md_week(c, person, monday)
67 c.run(f'codium {SCHOOL_DIR}/{person}.{monday}.md')
68
69 @task
70 def html_all(c, monday):
71 for person in STUDENTS:
72 missing(c, monday, person) # Warn on any missing subjects.
73 md_week(c, person, monday)
74 c.run(f'cd {SCHOOL_DIR};{BIN}/markdown_py {person}.{monday}.md > {SCHOOL_DIR}/{person}.{monday}.html')
75 c.run(f'cat {SCHOOL_DIR}/style.htm >> {SCHOOL_DIR}/{person}.{monday}.html')
76
77 @task
78 def preview_all(c, monday):
79 html_all(c, monday)
80 for person in STUDENTS:
81 c.run(f'librewolf {SCHOOL_DIR}/{person}.{monday}.html', asynchronous=True)
82
83 @task
84 def make_all(c, monday):
85 html_all(c, monday)
86 for person in STUDENTS:
87 html = f'{SCHOOL_DIR}/{person}.{monday}.html'
88 pdf = f'{SCHOOL_DIR}/{person}.{monday}.pdf'
89 HTML(html).write_pdf(pdf)
90 c.run(f'librewolf {SCHOOL_DIR}/{person}.{monday}.pdf', asynchronous=True)
91
92
93 def get_todays_assignments(df, date, person):
94 mine = df[df['person'] == person]
95 today = mine[mine['date'] == date]
96 return today
97
98 @task
99 def missing_on_day(c, person, day):
100 df = read_ods(ODS_FILE)
101 today = get_todays_assignments(df, day, person)
102 for subject in ['College Prep', 'Life Skills', 'Job Prep', 'Health Science']:
103 if not 'All Day Event' in today['subject'].values and not subject in today['subject'].values:
104 print(f'Missing {subject} for {person} on {day}')
105
106 @task
107 def missing(c, monday, person=None):
108
109 if not person:
110 for person in STUDENTS:
111 missing(c, monday, person)
112 else:
113 day = dt.strptime(monday, DATE_FORMAT)
114 for i in range(0,5):
115 missing_on_day(c, person, day.strftime(DATE_FORMAT))
116 day = day + timedelta(days=1)
117
118 @task
119 def print_day(c, person, date):
120 df = read_ods(ODS_FILE)
121 # df['date'] = pd.to_datetime(df['date'], format='%Y-%m-%d')
122 # today = df.loc(df['date'] >= '2026-01-12')
123 mine = df[df['person'] == person]
124 today = mine[mine['date'] == date]
125
126 weekday = dt.strptime(date, DATE_FORMAT).strftime('%A')
127
128 print()
129 print()
130 print(f"## {person}'s Assignments for {weekday}, {date}")
131
132
133 for subject, row in today.groupby('subject'):
134 print()
135 print()
136 subject = row['subject'].values[0]
137 minutes = int(row['minutes'].values[0])
138 print(f'### {subject} - {minutes} minutes')
139 print()
140 for task in row['task'].values:
141 print()
142 print(f'- [ ] {task}')
143 if(len(row['tip'].values) > 0):
144 for tip in row['tip'].values:
145 # Sometimes a float.
146 if hasattr(tip, 'strip'):
147 print()
148 print(f'> Tip: {tip.strip()}')
149
150 if(len(row['when_done'].values) > 0):
151 for tip in row['when_done'].values:
152 # Sometimes a float.
153 if hasattr(tip, 'strip'):
154 print()
155 print(f'**When done**: {tip.strip()}')
156
157 @task
158 def files(c):
159 folder(c, '.')
160
161
162 @task
163 def cleanup(c):
164 c.run(f'mv {SCHOOL_DIR}/*.md {ARCHIVE}')
165 c.run(f'mv {SCHOOL_DIR}/*.html {ARCHIVE}')
166
167 @task
168 def fresh_week(c):
169 cleanup(c)
170 c.run(f'mv {SCHOOL_DIR}/*.pdf {ARCHIVE}')
171
172
173 @task
174 def checklist(c):
175 print('- [ ] `fresh-week` to clean up old files.')
176 print('- [ ] update `Assignments/motd.txt` with an encouraging message for the week.')
177 print('- [ ] start libreoffice and open `assignements.ods`')
178 print('- [ ] copy a previous sheet to be the new first sheet, and update the date Monday date.')
179 print('- [ ] `invoke missing YYYY.MM.DD` the .ods file.')
180 print('- [ ] `invoke make-all YYYY.MM.DD` to generate PDF files')
181 print('- [ ] review the PDF files and recreate if needed.')
182 print('- [ ] share the PDF files in the family chat thrad.')
183
184