add semester/course planner
This commit is contained in:
parent
d9190cfdd3
commit
787d2bc904
84
generate.go
84
generate.go
|
@ -2,27 +2,59 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"os/exec"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
fileName = flag.String("file", "output.tex", "Name of output file")
|
fileName = flag.String("file", "output", "Name of output file")
|
||||||
tplPath = flag.String("tpl", "templates/daily-planner", "Path to templates")
|
tplPath = flag.String("tpl", "daily", "Path to templates")
|
||||||
startDate = flag.String("start", "", "date of start (yyy-mm-dd)")
|
startDate = flag.String("start", "", "date of start (yyy-mm-dd)")
|
||||||
days = flag.Int("days", 7, "number of days")
|
pages = flag.Int("pages", 7, "number of pages")
|
||||||
|
debug = flag.Bool("debug", false, "leave LaTeX log files")
|
||||||
output = os.Stdout
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
head := template.Must(template.ParseFiles(path.Join(*tplPath, "head.tpl")))
|
tmpfile, err := ioutil.TempFile("", "texgen")
|
||||||
body := template.Must(template.ParseFiles(path.Join(*tplPath, "body.tpl")))
|
defer os.Remove(tmpfile.Name()) // clean up
|
||||||
foot := template.Must(template.ParseFiles(path.Join(*tplPath, "foot.tpl")))
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
switch *tplPath {
|
||||||
|
case "daily":
|
||||||
|
daily(tmpfile)
|
||||||
|
case "class":
|
||||||
|
class(tmpfile)
|
||||||
|
default:
|
||||||
|
log.Fatal("Unknown template")
|
||||||
|
}
|
||||||
|
if err := tmpfile.Close(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("xelatex", "-halt-on-error", "-jobname="+*fileName, tmpfile.Name())
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !*debug {
|
||||||
|
os.Remove(*fileName + ".aux")
|
||||||
|
os.Remove(*fileName + ".log")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func class(file *os.File) {
|
||||||
|
head := template.Must(template.ParseFiles("templates/class/head.tpl"))
|
||||||
|
body := template.Must(template.ParseFiles("templates/class/body.tpl"))
|
||||||
|
foot := template.Must(template.ParseFiles("templates/class/foot.tpl"))
|
||||||
|
|
||||||
if *startDate == "" {
|
if *startDate == "" {
|
||||||
*startDate = time.Now().Format("2006-01-02")
|
*startDate = time.Now().Format("2006-01-02")
|
||||||
|
@ -30,17 +62,41 @@ func main() {
|
||||||
day, err := time.Parse("2006-01-02", *startDate)
|
day, err := time.Parse("2006-01-02", *startDate)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
check(head.Execute(output, nil))
|
check(head.Execute(file, nil))
|
||||||
for i := 0; i < *days; i++ {
|
for i := 0; i < *pages; i++ {
|
||||||
|
info := map[string]interface{}{
|
||||||
|
"Courses": []string{"C311", "C346", "C490"},
|
||||||
|
"Days": []string{"Monday", "Wednesday", "Other"},
|
||||||
|
"DateRange": fmt.Sprintf("%s-%s", day.Format("2006/01/02"), day.Add(24*time.Hour).Format("02")),
|
||||||
|
"Week": fmt.Sprintf("Week %d", i+1),
|
||||||
|
}
|
||||||
|
check(body.Execute(file, info))
|
||||||
|
day = day.Add(24 * time.Hour)
|
||||||
|
}
|
||||||
|
check(foot.Execute(file, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func daily(file *os.File) {
|
||||||
|
head := template.Must(template.ParseFiles("templates/daily/head.tpl"))
|
||||||
|
body := template.Must(template.ParseFiles("templates/daily/body.tpl"))
|
||||||
|
foot := template.Must(template.ParseFiles("templates/daily/foot.tpl"))
|
||||||
|
|
||||||
|
if *startDate == "" {
|
||||||
|
*startDate = time.Now().Format("2006-01-02")
|
||||||
|
}
|
||||||
|
day, err := time.Parse("2006-01-02", *startDate)
|
||||||
|
check(err)
|
||||||
|
|
||||||
|
check(head.Execute(file, nil))
|
||||||
|
for i := 0; i < *pages; i++ {
|
||||||
info := map[string]interface{}{
|
info := map[string]interface{}{
|
||||||
"Date": day.Format("2 Jan"),
|
"Date": day.Format("2 Jan"),
|
||||||
"DayOfWeek": day.Format("Monday"),
|
"DayOfWeek": day.Format("Monday"),
|
||||||
}
|
}
|
||||||
check(body.Execute(output, info))
|
check(body.Execute(file, info))
|
||||||
day = day.Add(24 * time.Hour)
|
day = day.Add(24 * time.Hour)
|
||||||
}
|
}
|
||||||
check(foot.Execute(output, nil))
|
check(foot.Execute(file, nil))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func check(err error) {
|
func check(err error) {
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
\begin{tabular}{ |r|r|p{35mm}|p{48mm}| }
|
||||||
|
\hline
|
||||||
|
\multicolumn{4}{|c|}{
|
||||||
|
\cellcolor{anti-flashwhite}
|
||||||
|
\noindent
|
||||||
|
\textbox{ {{.DateRange}} \hfill}
|
||||||
|
\textbox{\hfil Semester Planner \hfil}
|
||||||
|
\textbox{\hfill {{.Week}} }
|
||||||
|
}\\
|
||||||
|
\hline
|
||||||
|
\end{tabular}
|
||||||
|
|
||||||
|
\begin{tabular}{|m{1em}|m{\colwidth}|m{\colwidth}|m{\colwidth}|@{}m{0cm}@{}}\hline
|
||||||
|
{{range .Days}}& \centering\arraybackslash{ {{.}} } {{end}} \\\hline
|
||||||
|
{{range .Courses}}
|
||||||
|
\centering\rotatebox{90}{ {{.}} } &&& \\[75mm] \hline
|
||||||
|
{{end}}
|
||||||
|
\end{tabular}
|
|
@ -0,0 +1,67 @@
|
||||||
|
\documentclass[letter]{article}
|
||||||
|
%\input \jobname
|
||||||
|
|
||||||
|
\def \dayOfWeek{Week 9}
|
||||||
|
\def \date{2019/10/21-23}
|
||||||
|
\def \colwidth{56mm}
|
||||||
|
|
||||||
|
\usepackage[utf8]{inputenc}
|
||||||
|
\usepackage[letterpaper, margin=1cm]{geometry}
|
||||||
|
\usepackage{array}
|
||||||
|
\usepackage{graphicx}
|
||||||
|
\usepackage{colortbl}
|
||||||
|
\usepackage[x11names]{xcolor}
|
||||||
|
|
||||||
|
\pagenumbering{gobble}
|
||||||
|
|
||||||
|
\renewcommand{\arraystretch}{1.6}
|
||||||
|
|
||||||
|
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
|
||||||
|
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
|
||||||
|
\newcolumntype{S}{>{\centering\arraybackslash} m{.4\linewidth} }
|
||||||
|
|
||||||
|
\definecolor{anti-flashwhite}{rgb}{0.95, 0.95, 0.96}
|
||||||
|
|
||||||
|
\newcommand*{\grayline}{%
|
||||||
|
\arrayrulecolor{anti-flashwhite}
|
||||||
|
\cline{1-3}
|
||||||
|
\arrayrulecolor{black}
|
||||||
|
}
|
||||||
|
|
||||||
|
% TODO: Make this reactive
|
||||||
|
\newcommand\textbox[1]{%
|
||||||
|
\parbox{60.5mm}{#1}%
|
||||||
|
}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
\centering
|
||||||
|
|
||||||
|
\begin{tabular}{ |r|r|p{35mm}|p{48mm}| }
|
||||||
|
\hline
|
||||||
|
\multicolumn{4}{|c|}{
|
||||||
|
\cellcolor{anti-flashwhite}
|
||||||
|
\noindent
|
||||||
|
\textbox{\date \hfill}
|
||||||
|
\textbox{\hfil Semester Planner \hfil}
|
||||||
|
\textbox{\hfill \dayOfWeek}
|
||||||
|
}\\
|
||||||
|
\hline
|
||||||
|
\end{tabular}
|
||||||
|
|
||||||
|
\begin{tabular}{|m{1em}|m{\colwidth}|m{\colwidth}|m{\colwidth}|@{}m{0cm}@{}}\hline
|
||||||
|
& \centering Monday & \centering Wednesday & \centering\arraybackslash{Other} \\\hline
|
||||||
|
\centering\rotatebox{90}{C311} &&& \\[75mm] \hline
|
||||||
|
\centering\rotatebox{90}{C346} &&& \\[75mm] \hline
|
||||||
|
\centering\rotatebox{90}{C490} &&& \\[75mm] \hline
|
||||||
|
\end{tabular}
|
||||||
|
|
||||||
|
%\begin{tabular}{ |m{11mm}|C{54mm}|C{54mm}|C{54mm}| }
|
||||||
|
% \hline
|
||||||
|
% Course & Monday & Wednesday & Other \\\hline
|
||||||
|
% \rule{0pt}{78mm}C311 &&&\\\hline
|
||||||
|
% \rule{0pt}{78mm}C346 &&&\\\hline
|
||||||
|
% \rule{0pt}{78mm}C490 &&&\\\hline
|
||||||
|
%
|
||||||
|
%\end{tabular}
|
||||||
|
|
||||||
|
\end{document}
|
|
@ -0,0 +1 @@
|
||||||
|
\end{document}
|
|
@ -0,0 +1,38 @@
|
||||||
|
\documentclass[letter]{article}
|
||||||
|
%\input \jobname
|
||||||
|
|
||||||
|
\def \dayOfWeek{Week 9}
|
||||||
|
\def \date{2019/10/21-23}
|
||||||
|
\def \colwidth{56mm}
|
||||||
|
|
||||||
|
\usepackage[utf8]{inputenc}
|
||||||
|
\usepackage[letterpaper, margin=1cm]{geometry}
|
||||||
|
\usepackage{array}
|
||||||
|
\usepackage{graphicx}
|
||||||
|
\usepackage{colortbl}
|
||||||
|
\usepackage[x11names]{xcolor}
|
||||||
|
|
||||||
|
\pagenumbering{gobble}
|
||||||
|
|
||||||
|
\renewcommand{\arraystretch}{1.6}
|
||||||
|
|
||||||
|
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
|
||||||
|
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
|
||||||
|
\newcolumntype{S}{>{\centering\arraybackslash} m{.4\linewidth} }
|
||||||
|
|
||||||
|
\definecolor{anti-flashwhite}{rgb}{0.95, 0.95, 0.96}
|
||||||
|
|
||||||
|
\newcommand*{\grayline}{%
|
||||||
|
\arrayrulecolor{anti-flashwhite}
|
||||||
|
\cline{1-3}
|
||||||
|
\arrayrulecolor{black}
|
||||||
|
}
|
||||||
|
|
||||||
|
% TODO: Make this reactive
|
||||||
|
\newcommand\textbox[1]{%
|
||||||
|
\parbox{60.5mm}{#1}%
|
||||||
|
}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
\centering
|
||||||
|
|
Loading…
Reference in New Issue