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