]> us-delaporte.pagekite.me Git - dotfiles.git/blobdiff - invoke/school/tasks.py
Add invoke complete
[dotfiles.git] / invoke / school / tasks.py
index cb0079cd3b4f54b0c8bd9f18b4044d6e388d8d0e..5be7ba63c8434b2cc81c740dc8bd095266424f1d 100644 (file)
@@ -2,6 +2,7 @@
 from invoke import task
 from pandas_ods_reader import read_ods
 import pandas as pd
+import pdfkit
 
 from datetime import datetime as dt
 from datetime import timedelta
@@ -12,14 +13,27 @@ DATE_FORMAT = '%Y-%m-%d'
 TODAY = dt.now().strftime(DATE_FORMAT)
 
 SCHOOL_DIR = f'{HOME}/School/Assignments'
+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}")
+
+
 @task
-def open_assignments(c):
-    print("LibreOffice does not like to be launched this way.")
-    # c.run(f'libreoffice {ODS_FILE}', asynchronous=True)
+def open_folder(c):
+    folder(c, SCHOOL_DIR)
 
 
 @task
@@ -32,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))
@@ -43,7 +61,7 @@ def md_week(c, person, monday):
 
 
 @task
-def show_all(c, monday):
+def md_all(c, monday):
     for person in STUDENTS:
         md_week(c, person, monday)
         c.run(f'codium {SCHOOL_DIR}/{person}.{monday}.md')
@@ -51,11 +69,22 @@ def show_all(c, monday):
 @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 > {SCHOOL_DIR}/{person}.{monday}.html')
-        c.run(f'cat {SCHOOL_DIR}/style.html >> {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:
+        pdfkit.from_file(f'{SCHOOL_DIR}/{person}.{monday}.html', f'{SCHOOL_DIR}/{person}.{monday}.pdf', options={"enable-local-file-access": True})
 
 def get_todays_assignments(df, date, person):
     mine = df[df['person'] == person]
@@ -96,6 +125,7 @@ def print_day(c, person, date):
     print()
     print(f"## {person}'s Assignments for {weekday}, {date}")
 
+
     for subject, row in today.groupby('subject'):
         print()
         print()
@@ -121,3 +151,14 @@ def files(c):
     c.run('dolphin .')
 
 
+@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}')
+
+