]>
apps.delaporte.us Git - dotfiles.git/blob - invoke/school/tasks.py
1 from invoke
import task
2 from pandas_ods_reader
import read_ods
4 from weasyprint
import HTML
6 from datetime
import datetime
as dt
7 from datetime
import timedelta
10 HOME
= os
.path
.expanduser('~')
11 DATE_FORMAT
= '%Y-%m-%d'
12 TODAY
= dt
.now().strftime(DATE_FORMAT
)
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('|')
21 c
.run(f
"librewolf {url}", asynchronous
=True)
25 c
.run(f
"codium {path}")
29 # c.run(f'dolphin {path}', asynchronous=True)
30 # c.run(f"nemo {path}")
31 c
.run(f
'konsole --workdir {path}',asynchronous
=True)
41 df
= read_ods(ODS_FILE
)
46 def print_week(c
, person
, monday
):
47 print(f
'# {person}\'s Assignements for Week of {monday}')
49 motd
= open(f
'{SCHOOL_DIR}/motd.txt', 'r').read()
53 day
= dt
.strptime(monday
, DATE_FORMAT
)
55 print_day(c
, person
, day
.strftime(DATE_FORMAT
))
56 day
= day
+ timedelta(days
=1)
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')
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')
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')
78 def preview_all(c
, monday
):
80 for person
in STUDENTS
:
81 c
.run(f
'librewolf {SCHOOL_DIR}/{person}.{monday}.html', asynchronous
=True)
84 def make_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)
93 def get_todays_assignments(df
, date
, person
):
94 mine
= df
[df
['person'] == person
]
95 today
= mine
[mine
['date'] == date
]
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}')
107 def missing(c
, monday
, person
=None):
110 for person
in STUDENTS
:
111 missing(c
, monday
, person
)
113 day
= dt
.strptime(monday
, DATE_FORMAT
)
115 missing_on_day(c
, person
, day
.strftime(DATE_FORMAT
))
116 day
= day
+ timedelta(days
=1)
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
]
126 weekday
= dt
.strptime(date
, DATE_FORMAT
).strftime('%A')
130 print(f
"## {person}'s Assignments for {weekday}, {date}")
133 for subject
, row
in today
.groupby('subject'):
136 subject
= row
['subject'].values
[0]
137 minutes
= int(row
['minutes'].values
[0])
138 print(f
'### {subject} - {minutes} minutes')
140 for task
in row
['task'].values
:
142 print(f
'- [ ] {task}')
143 if(len(row
['tip'].values
) > 0):
144 for tip
in row
['tip'].values
:
146 if hasattr(tip
, 'strip'):
148 print(f
'> Tip: {tip.strip()}')
150 if(len(row
['when_done'].values
) > 0):
151 for tip
in row
['when_done'].values
:
153 if hasattr(tip
, 'strip'):
155 print(f
'**When done**: {tip.strip()}')
164 c
.run(f
'mv {SCHOOL_DIR}/*.md {ARCHIVE}')
165 c
.run(f
'mv {SCHOOL_DIR}/*.html {ARCHIVE}')
170 c
.run(f
'mv {SCHOOL_DIR}/*.pdf {ARCHIVE}')
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.')