Refactor, cleanup
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
credentials.json
|
credentials.json
|
||||||
token.json
|
token.json
|
||||||
|
.*.swp
|
||||||
|
|||||||
63
class.go
Normal file
63
class.go
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/api/calendar/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Class struct {
|
||||||
|
Summary string
|
||||||
|
Start string
|
||||||
|
End string
|
||||||
|
Students []string
|
||||||
|
Days []time.Weekday
|
||||||
|
Zoom string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Class) happensOnDay(t time.Time) bool {
|
||||||
|
for _, day := range c.Days {
|
||||||
|
if day == t.Weekday() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Class) buildEvent(t time.Time) *calendar.Event {
|
||||||
|
dateStr := t.Format("2006-01-02")
|
||||||
|
|
||||||
|
ev := &calendar.Event{
|
||||||
|
Summary: c.Summary,
|
||||||
|
Start: &calendar.EventDateTime{
|
||||||
|
DateTime: fmt.Sprintf("%sT%s:00", dateStr, c.Start),
|
||||||
|
TimeZone: "US/Pacific",
|
||||||
|
},
|
||||||
|
End: &calendar.EventDateTime{
|
||||||
|
DateTime: fmt.Sprintf("%sT%s:00", dateStr, c.End),
|
||||||
|
TimeZone: "US/Pacific",
|
||||||
|
},
|
||||||
|
Attendees: []*calendar.EventAttendee{},
|
||||||
|
}
|
||||||
|
|
||||||
|
attendees := c.Students
|
||||||
|
if len(attendees) == 0 {
|
||||||
|
attendees = allStudents
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, student := range attendees {
|
||||||
|
ev.Attendees = append(
|
||||||
|
ev.Attendees,
|
||||||
|
&calendar.EventAttendee{
|
||||||
|
Email: student,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Zoom != "" {
|
||||||
|
ev.Description = fmt.Sprintf(`Zoom: %s`, c.Zoom)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ev
|
||||||
|
}
|
||||||
127
classes.go
Normal file
127
classes.go
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var allStudents = []string{
|
||||||
|
"oliver.park@heliosns.org",
|
||||||
|
}
|
||||||
|
|
||||||
|
var greenStudents = []string{
|
||||||
|
"oliver.park@heliosns.org",
|
||||||
|
}
|
||||||
|
|
||||||
|
var weekDays = []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}
|
||||||
|
var weekDaysButFriday = []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday}
|
||||||
|
|
||||||
|
var classes = []Class {
|
||||||
|
Class{
|
||||||
|
Summary: "Morning Circle",
|
||||||
|
Start: "08:30",
|
||||||
|
End: "09:00",
|
||||||
|
Days: weekDaysButFriday,
|
||||||
|
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Community Meeting",
|
||||||
|
Start: "08:30",
|
||||||
|
End: "09:00",
|
||||||
|
Days: []time.Weekday{time.Friday},
|
||||||
|
Zoom: "https://zoom.us/j/96371462107",
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Math (Claudia & Rachel)",
|
||||||
|
Start: "09:00",
|
||||||
|
End: "09:40",
|
||||||
|
Days: weekDays,
|
||||||
|
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
||||||
|
Students: []string{
|
||||||
|
"oliver.park@heliosns.org",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Dreambox",
|
||||||
|
Start: "09:40",
|
||||||
|
End: "10:00",
|
||||||
|
Days: weekDays,
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Theme",
|
||||||
|
Start: "10:30",
|
||||||
|
End: "11:30",
|
||||||
|
Days: weekDaysButFriday,
|
||||||
|
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "SEL",
|
||||||
|
Start: "10:30",
|
||||||
|
End: "11:15",
|
||||||
|
Days: []time.Weekday{time.Friday},
|
||||||
|
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Literacy (Green)",
|
||||||
|
Start: "11:30",
|
||||||
|
End: "12:00",
|
||||||
|
Days: []time.Weekday{time.Monday, time.Wednesday},
|
||||||
|
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
||||||
|
Students: greenStudents,
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "PE (Yellow/Green)",
|
||||||
|
Start: "11:30",
|
||||||
|
End: "12:00",
|
||||||
|
Days: []time.Weekday{time.Tuesday},
|
||||||
|
Zoom: "https://zoom.us/j/97472507748?pwd=cW5vUFhyUjNTS2toWlZGN254U1ZqZz09",
|
||||||
|
Students: greenStudents,
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "iLab (Yellow/Green)",
|
||||||
|
Start: "11:30",
|
||||||
|
End: "12:00",
|
||||||
|
Days: []time.Weekday{time.Thursday},
|
||||||
|
Zoom: "https://us02web.zoom.us/j/86403635026?pwd=S2t1WkN2dnNJZlFkejdEbjRsUmNNUT09",
|
||||||
|
Students: greenStudents,
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Library",
|
||||||
|
Start: "11:30",
|
||||||
|
End: "12:00",
|
||||||
|
Days: []time.Weekday{time.Friday},
|
||||||
|
Zoom: "https://us02web.zoom.us/my/helioslibrary?pwd=cWd4RjNqNXZXNjRjM2dYQVhYeS9Xdz09",
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Spanish",
|
||||||
|
Start: "12:45",
|
||||||
|
End: "13:30",
|
||||||
|
Days: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday},
|
||||||
|
Zoom: "https://zoom.us/j/95144364579?pwd=cGdwNTZIOE42Y0syeVcwVEFhZ1JxZz09",
|
||||||
|
Students: []string{
|
||||||
|
"oliver.park@heliosns.org",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Music & Movement (Blue/Green)",
|
||||||
|
Start: "12:45",
|
||||||
|
End: "13:30",
|
||||||
|
Days: []time.Weekday{time.Friday},
|
||||||
|
Zoom: "https://zoom.us/j/96449009866?pwd=dlBHYUwxaDRReFhjVmRKZ0Vhdjdkdz09",
|
||||||
|
Students: greenStudents,
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Art (Blue/Green)",
|
||||||
|
Start: "14:00",
|
||||||
|
End: "14:45",
|
||||||
|
Days: []time.Weekday{time.Friday},
|
||||||
|
Zoom: "https://us02web.zoom.us/j/85434303018?pwd=c3EzQVNCMmk0L0o4bVF4QW85RTZHZz09",
|
||||||
|
Students: greenStudents,
|
||||||
|
},
|
||||||
|
Class{
|
||||||
|
Summary: "Closing Circle",
|
||||||
|
Start: "15:00",
|
||||||
|
End: "15:15",
|
||||||
|
Days: []time.Weekday{time.Friday},
|
||||||
|
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
||||||
|
},
|
||||||
|
}
|
||||||
173
main.go
173
main.go
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
@@ -14,137 +13,6 @@ import (
|
|||||||
var calName = flag.String("calendar", "", "name of calendar")
|
var calName = flag.String("calendar", "", "name of calendar")
|
||||||
var days = flag.Int("days", 0, "number of days in the future")
|
var days = flag.Int("days", 0, "number of days in the future")
|
||||||
|
|
||||||
var allStudents = []string{
|
|
||||||
"oliver.park@heliosns.org",
|
|
||||||
}
|
|
||||||
|
|
||||||
var greenStudents = []string{
|
|
||||||
"oliver.park@heliosns.org",
|
|
||||||
}
|
|
||||||
|
|
||||||
var weekDays = []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday}
|
|
||||||
var weekDaysButFriday = []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday}
|
|
||||||
|
|
||||||
var classes = []Class {
|
|
||||||
Class{
|
|
||||||
Summary: "Morning Circle",
|
|
||||||
Start: "08:30",
|
|
||||||
End: "09:00",
|
|
||||||
Days: weekDaysButFriday,
|
|
||||||
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Community Meeting",
|
|
||||||
Start: "08:30",
|
|
||||||
End: "09:00",
|
|
||||||
Days: []time.Weekday{time.Friday},
|
|
||||||
Zoom: "https://zoom.us/j/96371462107",
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Math (Claudia & Rachel)",
|
|
||||||
Start: "09:00",
|
|
||||||
End: "09:40",
|
|
||||||
Days: weekDays,
|
|
||||||
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
|
||||||
Students: []string{
|
|
||||||
"oliver.park@heliosns.org",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Dreambox",
|
|
||||||
Start: "09:40",
|
|
||||||
End: "10:00",
|
|
||||||
Days: weekDays,
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Theme",
|
|
||||||
Start: "10:30",
|
|
||||||
End: "11:30",
|
|
||||||
Days: weekDaysButFriday,
|
|
||||||
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "SEL",
|
|
||||||
Start: "10:30",
|
|
||||||
End: "11:15",
|
|
||||||
Days: []time.Weekday{time.Friday},
|
|
||||||
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Literacy (Green)",
|
|
||||||
Start: "11:30",
|
|
||||||
End: "12:00",
|
|
||||||
Days: []time.Weekday{time.Monday, time.Wednesday},
|
|
||||||
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
|
||||||
Students: greenStudents,
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "PE (Yellow/Green)",
|
|
||||||
Start: "11:30",
|
|
||||||
End: "12:00",
|
|
||||||
Days: []time.Weekday{time.Tuesday},
|
|
||||||
Zoom: "https://zoom.us/j/97472507748?pwd=cW5vUFhyUjNTS2toWlZGN254U1ZqZz09",
|
|
||||||
Students: greenStudents,
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "iLab (Yellow/Green)",
|
|
||||||
Start: "11:30",
|
|
||||||
End: "12:00",
|
|
||||||
Days: []time.Weekday{time.Thursday},
|
|
||||||
Zoom: "https://us02web.zoom.us/j/86403635026?pwd=S2t1WkN2dnNJZlFkejdEbjRsUmNNUT09",
|
|
||||||
Students: greenStudents,
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Library",
|
|
||||||
Start: "11:30",
|
|
||||||
End: "12:00",
|
|
||||||
Days: []time.Weekday{time.Friday},
|
|
||||||
Zoom: "https://us02web.zoom.us/my/helioslibrary?pwd=cWd4RjNqNXZXNjRjM2dYQVhYeS9Xdz09",
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Spanish",
|
|
||||||
Start: "12:45",
|
|
||||||
End: "13:30",
|
|
||||||
Days: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday},
|
|
||||||
Zoom: "https://zoom.us/j/95144364579?pwd=cGdwNTZIOE42Y0syeVcwVEFhZ1JxZz09",
|
|
||||||
Students: []string{
|
|
||||||
"oliver.park@heliosns.org",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Music & Movement (Blue/Green)",
|
|
||||||
Start: "12:45",
|
|
||||||
End: "13:30",
|
|
||||||
Days: []time.Weekday{time.Friday},
|
|
||||||
Zoom: "https://zoom.us/j/96449009866?pwd=dlBHYUwxaDRReFhjVmRKZ0Vhdjdkdz09",
|
|
||||||
Students: greenStudents,
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Art (Blue/Green)",
|
|
||||||
Start: "14:00",
|
|
||||||
End: "14:45",
|
|
||||||
Days: []time.Weekday{time.Friday},
|
|
||||||
Zoom: "https://us02web.zoom.us/j/85434303018?pwd=c3EzQVNCMmk0L0o4bVF4QW85RTZHZz09",
|
|
||||||
Students: greenStudents,
|
|
||||||
},
|
|
||||||
Class{
|
|
||||||
Summary: "Closing Circle",
|
|
||||||
Start: "15:00",
|
|
||||||
End: "15:15",
|
|
||||||
Days: []time.Weekday{time.Friday},
|
|
||||||
Zoom: "https://us02web.zoom.us/j/2274643506?pwd=Nm5NUXMwOVJKbEUzNE5VSkZCQzJ2UT09",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
type Class struct {
|
|
||||||
Summary string
|
|
||||||
Start string
|
|
||||||
End string
|
|
||||||
Students []string
|
|
||||||
Days []time.Weekday
|
|
||||||
Zoom string
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -192,50 +60,13 @@ func main() {
|
|||||||
|
|
||||||
for i := 0; i < *days; i++ {
|
for i := 0; i < *days; i++ {
|
||||||
date := now.Add(time.Duration(i * 24) * time.Hour)
|
date := now.Add(time.Duration(i * 24) * time.Hour)
|
||||||
dateStr := date.Format("2006-01-02")
|
|
||||||
|
|
||||||
for _, class := range classes {
|
for _, class := range classes {
|
||||||
found := false
|
if !class.happensOnDay(date) {
|
||||||
for _, day := range class.Days {
|
|
||||||
if day == date.Weekday() {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ev := &calendar.Event{
|
ev := class.buildEvent(date)
|
||||||
Summary: class.Summary,
|
|
||||||
Start: &calendar.EventDateTime{
|
|
||||||
DateTime: fmt.Sprintf("%sT%s:00", dateStr, class.Start),
|
|
||||||
TimeZone: "US/Pacific",
|
|
||||||
},
|
|
||||||
End: &calendar.EventDateTime{
|
|
||||||
DateTime: fmt.Sprintf("%sT%s:00", dateStr, class.End),
|
|
||||||
TimeZone: "US/Pacific",
|
|
||||||
},
|
|
||||||
Attendees: []*calendar.EventAttendee{},
|
|
||||||
}
|
|
||||||
|
|
||||||
attendees := class.Students
|
|
||||||
if len(attendees) == 0 {
|
|
||||||
attendees = allStudents
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, student := range attendees {
|
|
||||||
ev.Attendees = append(
|
|
||||||
ev.Attendees,
|
|
||||||
&calendar.EventAttendee{
|
|
||||||
Email: student,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if class.Zoom != "" {
|
|
||||||
ev.Description = fmt.Sprintf(`Zoom: %s`, class.Zoom)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := srv.Events.Insert(myCal.Id, ev).Do()
|
_, err := srv.Events.Insert(myCal.Id, ev).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user