forked from UTDNebula/api-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofessorParser.go
51 lines (41 loc) · 1.5 KB
/
professorParser.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 parser
import (
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/UTDNebula/api-tools/utils"
"github.com/UTDNebula/nebula-api/api/schema"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func parseProfessors(sectionId primitive.ObjectID, rowInfo map[string]*goquery.Selection, classInfo map[string]string) []primitive.ObjectID {
professorText := utils.TrimWhitespace(rowInfo["Instructor(s):"].Text())
professorMatches := personRegexp.FindAllStringSubmatch(professorText, -1)
var profRefs []primitive.ObjectID = make([]primitive.ObjectID, 0, len(professorMatches))
for _, match := range professorMatches {
nameStr := utils.TrimWhitespace(match[1])
names := strings.Split(nameStr, " ")
firstName := strings.Join(names[:len(names)-1], " ")
lastName := names[len(names)-1]
// Ignore blank names, because they exist for some reason???
if firstName == "" || lastName == "" {
continue
}
profKey := firstName + lastName
prof, profExists := Professors[profKey]
if profExists {
prof.Sections = append(prof.Sections, sectionId)
profRefs = append(profRefs, prof.Id)
continue
}
prof = &schema.Professor{}
prof.Id = primitive.NewObjectID()
prof.First_name = firstName
prof.Last_name = lastName
prof.Titles = []string{utils.TrimWhitespace(match[2])}
prof.Email = utils.TrimWhitespace(match[3])
prof.Sections = []primitive.ObjectID{sectionId}
profRefs = append(profRefs, prof.Id)
Professors[profKey] = prof
ProfessorIDMap[prof.Id] = profKey
}
return profRefs
}