]> us-delaporte.pagekite.me Git - dotfiles.git/blob - invoke/school/tasks.py
5be7ba63c8434b2cc81c740dc8bd095266424f1d
[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 import pdfkit
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
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 pdfkit.from_file(f'{SCHOOL_DIR}/{person}.{monday}.html', f'{SCHOOL_DIR}/{person}.{monday}.pdf', options={"enable-local-file-access": True})
88
89 def get_todays_assignments(df, date, person):
90 mine = df[df['person'] == person]
91 today = mine[mine['date'] == date]
92 return today
93
94 @task
95 def missing_on_day(c, person, day):
96 df = read_ods(ODS_FILE)
97 today = get_todays_assignments(df, day, person)
98 for subject in ['College Prep', 'Life Skills', 'Job Prep']:
99 if not 'All Day Event' in today['subject'].values and not subject in today['subject'].values:
100 print(f'Missing {subject} for {person} on {day}')
101
102 @task
103 def missing(c, monday, person=None):
104
105 if not person:
106 for person in STUDENTS:
107 missing(c, monday, person)
108 else:
109 day = dt.strptime(monday, DATE_FORMAT)
110 for i in range(0,5):
111 missing_on_day(c, person, day.strftime(DATE_FORMAT))
112 day = day + timedelta(days=1)
113
114 @task
115 def print_day(c, person, date):
116 df = read_ods(ODS_FILE)
117 # df['date'] = pd.to_datetime(df['date'], format='%Y-%m-%d')
118 # today = df.loc(df['date'] >= '2026-01-12')
119 mine = df[df['person'] == person]
120 today = mine[mine['date'] == date]
121
122 weekday = dt.strptime(date, DATE_FORMAT).strftime('%A')
123
124 print()
125 print()
126 print(f"## {person}'s Assignments for {weekday}, {date}")
127
128
129 for subject, row in today.groupby('subject'):
130 print()
131 print()
132 print(f'### {row["subject"].values[0]}')
133 print()
134 for task in row['task'].values:
135 print()
136 print(f'- [ ] {task}')
137 if(len(row['tip'].values) > 0):
138 for tip in row['tip'].values:
139 if tip:
140 print()
141 print(f'> Tip: {tip}')
142
143 if(len(row['when_done'].values) > 0):
144 for tip in row['when_done'].values:
145 if tip:
146 print()
147 print(f'**When done**: {tip}')
148
149 @task
150 def files(c):
151 c.run('dolphin .')
152
153
154 @task
155 def cleanup(c):
156 c.run(f'mv {SCHOOL_DIR}/*.md {ARCHIVE}')
157 c.run(f'mv {SCHOOL_DIR}/*.html {ARCHIVE}')
158
159 @task
160 def fresh_week(c):
161 cleanup(c)
162 c.run(f'mv {SCHOOL_DIR}/*.pdf {ARCHIVE}')
163
164