-
Notifications
You must be signed in to change notification settings - Fork 1
/
exam.go
41 lines (35 loc) · 1.04 KB
/
exam.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
package main
import (
"strconv"
"github.com/PuerkitoBio/goquery"
"github.com/gocolly/colly"
)
type ExamTime struct {
Crn string `gorm:"notNull"`
SemesterID int `gorm:"column:semester;not null"`
Semester Semester `gorm:"constraint:OnDelete:CASCADE;"`
Identifier string `gorm:"primaryKey"`
Time string `gorm:"notNull"`
Location string `gorm:"notNull"`
}
func exams(semester int) {
c := colly.NewCollector()
c.OnHTML("table.bordertable", func(e *colly.HTMLElement) {
e.DOM.Find("tr").Each(func(i int, s *goquery.Selection) {
selection := s.Find("td.dbdefault")
if len(selection.Nodes) == 0 {
return
}
crn := selection.Next().Next().Next().First().Text()
db.Save(&ExamTime{
Crn: crn,
SemesterID: semester,
Identifier: crn + strconv.Itoa(semester),
Time: selection.Last().Prev().Text(),
Location: selection.Last().Text(),
})
})
})
c.Visit("https://selfservice.mun.ca/direct/swkgexm.P_Query_Exam?p_term_code=" + strconv.Itoa(semester) + "&p_title=")
c.Wait()
}