-
Notifications
You must be signed in to change notification settings - Fork 0
/
lectures.go
71 lines (59 loc) · 1.16 KB
/
lectures.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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"fmt"
"time"
"github.com/tidwall/buntdb"
)
type lecture struct {
Title string `json:"title"`
Start string `json:"start"`
Presenter string `json:"presenter"`
}
func loadLectures(db *buntdb.DB) {
content, err := ioutil.ReadFile("./data/lectures.json")
if err != nil {
log.Fatal(err)
return
}
var list []lecture
err = json.Unmarshal(content, &list)
if err != nil {
log.Fatal(err)
return
}
for _, it := range list {
err = initLecture(db, it)
if err != nil {
log.Fatal(err)
return
}
}
}
func initLecture(db *buntdb.DB, lec lecture) error {
start, err := time.ParseInLocation("2006-01-02 15:04", lec.Start, time.Local)
if err != nil {
return err
}
key := makeSpectacleKey(lec.Title)
_, err = getString(db, key)
if err == nil {
// TODO update existing lecture
return nil
}
spec := &Spectacle{
Type: "lecture",
Title: lec.Title,
PresenterName: lec.Presenter,
Start: start.UTC(),
Duration: 1,
}
spec.Created("robot")
err = insert(db, spec)
if err == nil {
fmt.Printf("lecture '%s' initialized\n", lec.Title)
}
return err
}