X-Git-Url: https://apps.delaporte.us/gitweb/dotfiles.git/blobdiff_plain/d6d2d8e00c52d4f2dc6ad1ef3a91a013a9b7058c..7b7663b9c3de414e6c01c96a5974b3d6b2ff9efe:/invoke/school/tasks.py diff --git a/invoke/school/tasks.py b/invoke/school/tasks.py index b1dbdca..03610dd 100644 --- a/invoke/school/tasks.py +++ b/invoke/school/tasks.py @@ -1,7 +1,7 @@ -# This file is meant to sit in ~ for use from all shells. from invoke import task from pandas_ods_reader import read_ods import pandas as pd +from weasyprint import HTML from datetime import datetime as dt from datetime import timedelta @@ -12,10 +12,29 @@ DATE_FORMAT = '%Y-%m-%d' TODAY = dt.now().strftime(DATE_FORMAT) SCHOOL_DIR = f'{HOME}/School/Assignments' -ODS_FILE = f'{HOME}/School/Assignments/tasks.ods' +ARCHIVE = f'{SCHOOL_DIR}/archive' +ODS_FILE = f'{HOME}/School/Assignments/assignments.ods' BIN = f'{HOME}/envs/invoke/bin' STUDENTS = os.environ.get('STUDENTS').split('|') +def browse(c, url): + c.run(f"librewolf {url}", asynchronous=True) + + +def code(c, path): + c.run(f"codium {path}") + + +def folder(c, path): + # c.run(f'dolphin {path}', asynchronous=True) + c.run(f"nemo {path}", asynchronous=True) + # c.run(f'konsole --workdir {path}',asynchronous=True) + + +@task +def open_folder(c): + folder(c, SCHOOL_DIR) + @task def dump_ods(c): @@ -27,6 +46,10 @@ def dump_ods(c): def print_week(c, person, monday): print(f'# {person}\'s Assignements for Week of {monday}') + motd = open(f'{SCHOOL_DIR}/motd.txt', 'r').read() + print(motd) + + day = dt.strptime(monday, DATE_FORMAT) for i in range(0,5): print_day(c, person, day.strftime(DATE_FORMAT)) @@ -34,22 +57,38 @@ def print_week(c, person, monday): @task def md_week(c, person, monday): - c.run(f'cd {SCHOOL_DIR};{BIN}/invoke print-week {person} {monday} > {person}.{monday}.md') + c.run(f'cd {SCHOOL_DIR};{BIN}/invoke print-week {person} {monday} > {SCHOOL_DIR}/{person}.{monday}.md') @task -def show_all(c, monday): +def md_all(c, monday): for person in STUDENTS: md_week(c, person, monday) - c.run(f'codium {person}.{monday}.md') + c.run(f'codium {SCHOOL_DIR}/{person}.{monday}.md') @task def html_all(c, monday): for person in STUDENTS: + missing(c, monday, person) # Warn on any missing subjects. md_week(c, person, monday) - c.run(f'cd {SCHOOL_DIR};{BIN}/markdown_py {person}.{monday}.md > {person}.{monday}.html') - c.run(f'librewolf {person}.{monday}.html') + c.run(f'cd {SCHOOL_DIR};{BIN}/markdown_py {person}.{monday}.md > {SCHOOL_DIR}/{person}.{monday}.html') + c.run(f'cat {SCHOOL_DIR}/style.htm >> {SCHOOL_DIR}/{person}.{monday}.html') + +@task +def preview_all(c, monday): + html_all(c, monday) + for person in STUDENTS: + c.run(f'librewolf {SCHOOL_DIR}/{person}.{monday}.html', asynchronous=True) +@task +def make_all(c, monday): + html_all(c, monday) + for person in STUDENTS: + html = f'{SCHOOL_DIR}/{person}.{monday}.html' + pdf = f'{SCHOOL_DIR}/{person}.{monday}.pdf' + HTML(html).write_pdf(pdf) + c.run(f'librewolf {SCHOOL_DIR}/{person}.{monday}.pdf', asynchronous=True) + def get_todays_assignments(df, date, person): mine = df[df['person'] == person] @@ -60,8 +99,8 @@ def get_todays_assignments(df, date, person): def missing_on_day(c, person, day): df = read_ods(ODS_FILE) today = get_todays_assignments(df, day, person) - for subject in ['College Prep', 'Life Skills', 'Job Prep']: - if not subject in today['subject'].values: + for subject in ['College Prep', 'Life Skills', 'Job Prep', 'Health Science']: + if not 'All Day Event' in today['subject'].values and not subject in today['subject'].values: print(f'Missing {subject} for {person} on {day}') @task @@ -90,22 +129,56 @@ def print_day(c, person, date): print() print(f"## {person}'s Assignments for {weekday}, {date}") - for _, row in today.iterrows(): + + for subject, row in today.groupby('subject'): print() print() - print(f'### {row["subject"]}') + subject = row['subject'].values[0] + minutes = int(row['minutes'].values[0]) + print(f'### {subject} - {minutes} minutes') print() - print(row['task']) - if(row['tip']): + for task in row['task'].values: print() - print(f'> Tip: {row["tip"]}') - - if(row['when_done']): - print() - print(f'**When done**: {row["when_done"]}') + print(f'- [ ] {task}') + if(len(row['tip'].values) > 0): + for tip in row['tip'].values: + # Sometimes a float. + if hasattr(tip, 'strip'): + print() + print(f'> Tip: {tip.strip()}') + + if(len(row['when_done'].values) > 0): + for tip in row['when_done'].values: + # Sometimes a float. + if hasattr(tip, 'strip'): + print() + print(f'**When done**: {tip.strip()}') @task def files(c): - c.run('dolphin .') + folder(c, '.') + + +@task +def cleanup(c): + c.run(f'mv {SCHOOL_DIR}/*.md {ARCHIVE}') + c.run(f'mv {SCHOOL_DIR}/*.html {ARCHIVE}') + +@task +def fresh_week(c): + cleanup(c) + c.run(f'mv {SCHOOL_DIR}/*.pdf {ARCHIVE}') + + +@task +def checklist(c): + print('- [ ] `fresh-week` to clean up old files.') + print('- [ ] update `Assignments/motd.txt` with an encouraging message for the week.') + print('- [ ] start libreoffice and open `assignements.ods`') + print('- [ ] copy a previous sheet to be the new first sheet, and update the date Monday date.') + print('- [ ] `invoke missing YYYY.MM.DD` the .ods file.') + print('- [ ] `invoke make-all YYYY.MM.DD` to generate PDF files') + print('- [ ] review the PDF files and recreate if needed.') + print('- [ ] share the PDF files in the family chat thrad.')