-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrawl.go
51 lines (43 loc) · 1.69 KB
/
crawl.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
package main
import (
"./core"
"google.golang.org/api/calendar/v3"
"os"
"fmt"
"sync"
)
func main() {
args := os.Args[1:]
// TODO: In the future, we should load all the calendars from a text/JSON file online --Matthew
// GOOGLE CAL URLS
google_cals := make(map[string]string)
// acm club: http://acm.engr.scu.edu/events
google_cals["acm"] = "https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?key=AIzaSyCnRyFyPuJ9WSeu602Q7CE13TsxWVNbw10&timeMin=2018-02-24T00:00:00Z&timeMax=2030-04-09T00:00:00Z&singmaxResults=9999&_=1520708172234"
// Official CSO/RSO Calendar
google_cals["cso"] = "https://www.googleapis.com/calendar/v3/calendars/[email protected]/[email protected]&key=AIzaSyCnRyFyPuJ9WSeu602Q7CE13TsxWVNbw10&&timeMin=2018-02-24T00:00:00Z&timeMax=2099-04-09T00:00:00Z&singmaxResults=9999&_=1520708172234"
// Engineering Student Events Calendar - https://www.scu.edu/engineering/beyond-the-classroom/student-organizations/
google_cals["engr"] = "https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?key=AIzaSyCnRyFyPuJ9WSeu602Q7CE13TsxWVNbw10&timeMin=2018-02-24T00:00:00Z&timeMax=2030-04-09T00:00:00Z&singmaxResults=9999&_=1520708172234"
var wg sync.WaitGroup
wg.Add(len(args))
events_ch := make(chan []calendar.Event)
for _, arg := range args {
go func(url string) {
defer wg.Done()
events, err := core.CrawlGoogleCal(url)
if err == nil {
wg.Add(len(args))
events_ch <- events
} else {
panic(err)
}
}(google_cals[arg])
}
go func() {
for events := range events_ch {
defer wg.Done()
fmt.Printf("%d", len(events))
core.AddEvents(events)
}
}()
wg.Wait()
}