-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
105 lines (87 loc) · 3.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
"strconv"
"time"
"github.com/nguyenthenguyen/docx"
)
// Go forth and create an agenda.
func main() {
nt := nextTuesday(time.Now())
fmt.Println("Generating Agenda for", monthDayCommaYear(nt))
if err := createDoc(nt); err != nil {
panic(err)
}
}
// Creates a word document with the Name DD.MM.YYYY.docx based on Agenda.docx.
func createDoc(t time.Time) error {
r, err := docx.ReadDocxFile("./Agenda.docx")
defer r.Close()
if err != nil {
return err
}
d := r.Editable()
if err := replaceFields(d, t); err != nil {
return err
}
d.WriteToFile("./" + formatDate(t, delimiterPeriods) + ".docx")
return nil
}
// ReplaceSpeakers replaces the speech time, speaker, speech, Evaluator time, and Evaluator.
func replaceSpeakers(d *docx.Docx, s []*Speaker) {
// Time for Speech evaluation goals starts at 7:13 pm.
curTime := time.Date(2017, time.January, 1, 7, 13, 0, 0, time.UTC)
nextTime, _ := addMinutes(curTime, 0)
var pastSpeechTime int
var printString string
for i, speaker := range s {
speechOrder := i + 1
soString := strconv.Itoa(speechOrder)
d.Replace("evaluator"+soString, speaker.Evaluator, -1)
d.Replace("speaker"+soString+"FirstLastName", speaker.Name, -1)
d.Replace("firstName"+soString, speaker.firstName(), -1)
d.Replace("speaker"+soString+"Manual", speaker.Speech.ManualName, -1)
d.Replace("speaker"+soString+"Speech", speaker.Speech.info(), -1)
// Replace Speech times for Speaker and Evaluator based on last Max Speech time plus one.
nextTime, printString = addMinutes(nextTime, pastSpeechTime)
d.Replace("e"+soString+"t"+soString, printString, 1)
nextTime, printString = addMinutes(nextTime, +1)
d.Replace("s"+soString+"t"+soString, printString, 1)
pastSpeechTime = speaker.Speech.Max + 1
}
_, ttTime := addMinutes(nextTime, pastSpeechTime)
d.Replace("ttmt", ttTime, 1)
}
// ReplaceFutureWeeks replaces the future schedule on the agenda.
func replaceFutureWeeks(d *docx.Docx, fw [][]string) {
for i, nextWeek := range fw {
for j := range nextWeek {
d.Replace("w"+strconv.Itoa(i)+"_"+strconv.Itoa(j), nextWeek[j], 1)
}
}
}
// ReplaceFields handles the replacement of all the placeholders in the agenda.
func replaceFields(d *docx.Docx, t time.Time) error {
roles, err := NewAgendaRoles(formatDate(t, delimiterSlashes))
if err != nil {
return err
}
d.ReplaceHeader("Date", monthDayCommaYear(t))
d.Replace("president", roles.BoardMembers.President, -1)
d.Replace("vpe", roles.BoardMembers.VPE, -1)
d.Replace("vpm", roles.BoardMembers.VPM, -1)
d.Replace("vppr", roles.BoardMembers.VPPR, -1)
d.Replace("secretary", roles.BoardMembers.Secretary, -1)
d.Replace("treasurer", roles.BoardMembers.Treasurer, -1)
d.Replace("saa", roles.BoardMembers.SAA, -1)
d.Replace("jokeMaster", roles.JokeMaster, -1)
d.Replace("toastmasterOfDay", roles.Toastmaster, -1)
d.Replace("generalEval", roles.GE, -1)
d.Replace("timer", roles.Timer, -1)
d.Replace("ah-counter", roles.AhCounter, -1)
d.Replace("grammarian", roles.Grammarian, -1)
d.Replace("tTMaster", roles.TableTopicsMaster, -1)
replaceSpeakers(d, roles.Speakers)
replaceFutureWeeks(d, roles.FutureWeeks)
return nil
}