From 871b6ef5959e45c6a23cd0c1aed287018871e07a Mon Sep 17 00:00:00 2001 From: Justin Schwerdtfeger Date: Sat, 14 Nov 2026 01:11:12 +0000 Subject: [PATCH 1/6] Use Nebula API eval schema branch as reference (be sure to revert this before merge) --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 55966caf..4c074f6d 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.26.0 require ( github.com/PuerkitoBio/goquery v1.12.0 - github.com/UTDNebula/nebula-api v1.2.1-0.20261005155620-603b6b10f3ec + github.com/UTDNebula/nebula-api v1.2.1-0.20261114001700-6f26423dffba github.com/chromedp/cdproto v0.0.0-20260321001828-e3e3800016bc github.com/chromedp/chromedp v0.15.1 github.com/dongri/phonenumber v0.1.12 @@ -37,7 +37,7 @@ require ( github.com/envoyproxy/go-control-plane/envoy v1.39.0 // indirect github.com/envoyproxy/protoc-gen-validate v1.3.3 // indirect github.com/felixge/httpsnoop v1.1.0 // indirect - github.com/go-jose/go-jose/v4 v4.1.4 // indirect + github.com/go-jose/go-jose/v4 v4.1.6 // indirect github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 // indirect github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect diff --git a/go.sum b/go.sum index d36c3e73..c7b14fd3 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapp github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.60.0/go.mod h1:SRAbhyZ4R4FagHMM9VtRgSY/lheRoht2fKelZXQUenk= github.com/PuerkitoBio/goquery v1.12.0 h1:pAcL4g3WRXekcB9AU/y1mbKez2dbY2AajVhtkO8RIBo= github.com/PuerkitoBio/goquery v1.12.0/go.mod h1:802ej+gV2y7bbIhOIoPY5sT183ZW0YFofScC4q/hIpQ= -github.com/UTDNebula/nebula-api v1.2.1-0.20261005155620-603b6b10f3ec h1:8tR4hi5XnNjmz4M6tWveIP0P4qiP8CxIRxyfFMdggAc= -github.com/UTDNebula/nebula-api v1.2.1-0.20261005155620-603b6b10f3ec/go.mod h1:OoCuc8ktZCTZwO17bIz8bXwt06KIW8NYvzVvZ/8TbWc= +github.com/UTDNebula/nebula-api v1.2.1-0.20261114001700-6f26423dffba h1:+PHtw9NHmgPUCbvWP0rv4aR7D+aPUcwR2lMZlwtizCw= +github.com/UTDNebula/nebula-api v1.2.1-0.20261114001700-6f26423dffba/go.mod h1:ckjoQ1cy323RvxYfGpmLFUYwb3pXSOvT7V0sCzPnFp4= github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -62,8 +62,8 @@ github.com/getsentry/sentry-go v0.48.0 h1:FRZNr7Uk1C86ev1bSJmYlUkL9oyivQA6YOcdYf github.com/getsentry/sentry-go v0.48.0/go.mod h1:E5UkA5wp1qR2+MDydNYlVeUiNN2xEdjYMidkgf0Qoss= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= -github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA= -github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= +github.com/go-jose/go-jose/v4 v4.1.6 h1:sNRkftxFJxwsILiQukqp5z83QBSmntVwmgRY7AqBDO4= +github.com/go-jose/go-jose/v4 v4.1.6/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 h1:vymEbVwYFP/L05h5TKQxvkXoKxNvTpjxYKdF1Nlwuao= github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= From 760acf04118055bce6535d52fe2472f2f43071e0 Mon Sep 17 00:00:00 2001 From: Justin Schwerdtfeger Date: Sat, 14 Nov 2026 02:10:37 +0000 Subject: [PATCH 2/6] Add scraped_at.txt to coursebook scraper --- scrapers/coursebook.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scrapers/coursebook.go b/scrapers/coursebook.go index 539b6a8c..0fe87efc 100644 --- a/scrapers/coursebook.go +++ b/scrapers/coursebook.go @@ -106,6 +106,9 @@ func ScrapeCoursebook(term string, startPrefix string, outDir string, resume boo if err := scraper.validate(); err != nil { log.Fatal("Validating failed: ", err) } + if err := scraper.writeScrapedAt(); err != nil { + log.Fatal(err) + } } type coursebookScraper struct { @@ -188,6 +191,15 @@ func (s *coursebookScraper) ensureOutputFolder() error { return nil } +// writeScrapedAt records one UTC completion time for all sections in the term. +func (s *coursebookScraper) writeScrapedAt() error { + if err := s.ensureOutputFolder(); err != nil { + return err + } + path := filepath.Join(s.outDir, s.term, "scraped_at.txt") + return os.WriteFile(path, []byte(time.Now().UTC().Format(time.RFC3339)+"\n"), 0644) +} + // ensurePrefixFolder creates {outDir}/term/prefix if it does not exist func (s *coursebookScraper) ensurePrefixFolder(prefix string) error { if err := os.MkdirAll(filepath.Join(s.outDir, s.term, prefix), 0755); err != nil { From 410b160362dd8c64c877e4470b84be4fbda9ecde Mon Sep 17 00:00:00 2001 From: Justin Schwerdtfeger Date: Sat, 14 Nov 2026 02:30:54 +0000 Subject: [PATCH 3/6] Initial Enrollment Parser --- parser/parser.go | 38 +++++++++++++++++++++++- parser/sectionParser.go | 66 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index c7aa7455..6fe79763 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -5,6 +5,8 @@ import ( "fmt" "log" "os" + "path/filepath" + "strings" "time" "github.com/UTDNebula/api-tools/utils" @@ -128,11 +130,45 @@ func parse(path string) { panic(err) } - parseSection(getRowInfo(doc), getClassInfo(doc)) + parseSection(getRowInfo(doc), getClassInfo(doc), getScrapedAt(path)) utils.VPrint("Parsed!") } +// getScrapedAt finds the timestamp file in the HTML file's directory +// or its parent directories. +func getScrapedAt(path string) *time.Time { + dir, err := filepath.Abs(filepath.Dir(path)) + if err != nil { + panic(err) + } + + // Find scraped_at timestamp for this semester by searching parents + for { + timestampPath := filepath.Join(dir, "scraped_at.txt") + data, err := os.ReadFile(timestampPath) + if err == nil { + scrapedAt, err := time.Parse(time.RFC3339, strings.TrimSpace(string(data))) + if err != nil { + panic(fmt.Errorf("invalid scrape timestamp %s: %w", timestampPath, err)) + } + scrapedAt = scrapedAt.UTC() + return &scrapedAt + } + + if !os.IsNotExist(err) { + panic(err) + } + + + parent := filepath.Dir(dir) + if parent == dir { + return nil + } + dir = parent + } +} + func getRowInfo(doc *goquery.Document) map[string]*goquery.Selection { infoRows := doc.FindMatcher(goquery.Single("table.courseinfo__overviewtable > tbody")).ChildrenFiltered("tr") rowInfo := make(map[string]*goquery.Selection, len(infoRows.Nodes)) diff --git a/parser/sectionParser.go b/parser/sectionParser.go index 62d22d7b..957f80bf 100644 --- a/parser/sectionParser.go +++ b/parser/sectionParser.go @@ -1,7 +1,9 @@ package parser import ( + "fmt" "regexp" + "strconv" "strings" "time" @@ -33,12 +35,15 @@ var ( // meetingTimesRegexp matches a time in 12-hour AM/PM format (e.g., "5:00 pm", "11:30am") meetingTimesRegexp = regexp.MustCompile(utils.R_TIME_AM_PM) + + // enrollmentComponentRegexp matches enrollment total (may list counts for cross-listed sections (e.g. Enrolled Total: 14 (acn5312.002.26f) + 0 (hcs5312.002.26f)) + enrollmentComponentRegexp = regexp.MustCompile(`^([0-9]+)(?:\s+\(([^()]+)\))?$`) ) // parseSection creates a schema.Section from rowInfo and ClassInfo, // adds it to Sections, and updates the associated Course and Professors. // Internally calls parseCourse and parseProfessors, which modify global maps. -func parseSection(rowInfo map[string]*goquery.Selection, classInfo map[string]string) { +func parseSection(rowInfo map[string]*goquery.Selection, classInfo map[string]string, scrapedAt *time.Time) { classNum, courseNum := getInternalClassAndCourseNum(classInfo) session := getAcademicSession(rowInfo) courseRef := parseCourse(courseNum, session, rowInfo, classInfo) @@ -60,6 +65,7 @@ func parseSection(rowInfo map[string]*goquery.Selection, classInfo map[string]st Core_flags: getCoreFlags(rowInfo), Syllabus_uri: getSyllabusUri(rowInfo), Grade_distribution: getGradeDistribution(session, sectionNumber, courseRef), + Latest_enrollment: getEnrollment(rowInfo, scrapedAt), } // Add new section to section map @@ -165,6 +171,64 @@ func getInstructionMode(classInfo map[string]string) string { return "" } +// getEnrollment reads the labeled values in CourseBook's Status row. +// A missing row or count stays absent rather than becoming a reported zero. +func getEnrollment(rowInfo map[string]*goquery.Selection, scrapedAt *time.Time) *schema.Enrollment { + row, ok := rowInfo["Status:"] + if !ok { + return nil + } + + values := make(map[string]string) + var label string + row.Contents().Each(func(_ int, s *goquery.Selection) { + if goquery.NodeName(s) == "b" { + label = strings.Join(strings.Fields(s.Text()), " ") + } else { + values[label] += s.Text() + } + }) + + parseCount := func(label string, allowNegative bool) *int { + value := strings.TrimSpace(values[label]) + if value == "" { + return nil + } + count, err := strconv.Atoi(value) + if err != nil || (!allowNegative && count < 0) { + panic(fmt.Sprintf("invalid %s %q", label, value)) + } + return &count + } + + enrollment := &schema.Enrollment{ + Scraped_at: scrapedAt, + Status: strings.TrimSpace(values["Enrollment Status:"]), + Available_seats: parseCount("Available Seats:", true), + Waitlist: parseCount("Waitlist:", false), + } + if value := strings.TrimSpace(values["Enrolled Total:"]); value != "" { + total := 0 + components := strings.Split(value, "+") + for _, component := range components { + match := enrollmentComponentRegexp.FindStringSubmatch(strings.TrimSpace(component)) + if match == nil || (len(components) > 1 && match[2] == "") { + panic(fmt.Sprintf("invalid Enrolled Total: %q", value)) + } + count, err := strconv.Atoi(match[1]) + if err != nil { + panic(err) + } + total += count + } + enrollment.Enrolled_total = &total + } + if enrollment.Status == "" && enrollment.Available_seats == nil && enrollment.Enrolled_total == nil && enrollment.Waitlist == nil { + return nil + } + return enrollment +} + // getMeetings parses meeting schedule information from the row information map. // // The function does not guarantee any number of meetings nor any fields of From 6ac36cd76430254221ab5da9270553cafea9a390 Mon Sep 17 00:00:00 2001 From: Justin Schwerdtfeger Date: Sat, 14 Nov 2026 02:53:57 +0000 Subject: [PATCH 4/6] Update tests --- parser/fixtures/enrollment.json | 17 +++++++++ parser/parser_test.go | 10 ++++++ parser/sectionParser_test.go | 50 +++++++++++++++++++++++++++ parser/testdata/case_000/section.json | 9 ++++- parser/testdata/case_001/section.json | 9 ++++- parser/testdata/case_002/section.json | 9 ++++- parser/testdata/case_003/section.json | 9 ++++- parser/testdata/case_004/section.json | 9 ++++- parser/testdata/case_005/section.json | 9 ++++- parser/testdata/case_006/section.json | 9 ++++- parser/testdata/scraped_at.txt | 1 + parser/testdata/sections.json | 49 ++++++++++++++++++++++++++ 12 files changed, 183 insertions(+), 7 deletions(-) create mode 100644 parser/fixtures/enrollment.json create mode 100644 parser/testdata/scraped_at.txt diff --git a/parser/fixtures/enrollment.json b/parser/fixtures/enrollment.json new file mode 100644 index 00000000..b6d957bd --- /dev/null +++ b/parser/fixtures/enrollment.json @@ -0,0 +1,17 @@ +[ + { + "name": "closed", + "source": "data/26f/cp_acct/acct2301.014.26f.html", + "html": "\n \n \n
\n Status:\n \n Enrollment Status: CLOSED/FULL    Available Seats: 0    Enrolled Total: 68    Waitlist: 0\n\n
" + }, + { + "name": "cross_listed", + "source": "data/26f/cp_bims/bims4v00.001.26f.html", + "html": "\n \n \n
\n Status:\n \n Enrollment Status: OPEN    Available Seats: 10    Enrolled Total: 1 (bims4v00.001.26f) + 8 (phys4v11.001.26f) + 5 (phys5v48.001.26f)    Waitlist: 0\n\n
" + }, + { + "name": "over_enrolled", + "source": "data/26f/cp_buan/buan4382.501.26f.html", + "html": "\n \n \n
\n Status:\n \n Enrollment Status: CLOSED/FULL    Available Seats: -15    Enrolled Total: 23 (buan4382.501.26f) + 34 (itss4382.501.26f)    Waitlist: 0\n\n
" + } +] diff --git a/parser/parser_test.go b/parser/parser_test.go index f851ba8c..af0095b6 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -132,6 +132,16 @@ func updateTestData() error { } defer os.RemoveAll(tempDir) + // Keep the shared scrape timestamp when regenerating the fixture tree. + timestampPath := filepath.Join("testdata", "scraped_at.txt") + if data, err := os.ReadFile(timestampPath); err == nil { + if err := os.WriteFile(filepath.Join(tempDir, "scraped_at.txt"), data, 0644); err != nil { + return err + } + } else if !os.IsNotExist(err) { + return err + } + GradeMap, err = loadGrades("../static-data/grades") if err != nil { return err diff --git a/parser/sectionParser_test.go b/parser/sectionParser_test.go index a920b4d1..215e0786 100644 --- a/parser/sectionParser_test.go +++ b/parser/sectionParser_test.go @@ -2,12 +2,62 @@ package parser import ( "fmt" + "os" + "path/filepath" + "strings" "testing" "time" + "github.com/PuerkitoBio/goquery" + "github.com/UTDNebula/nebula-api/rest/schema" "github.com/google/go-cmp/cmp" ) +func TestGetEnrollment(t *testing.T) { + fixtures, err := unmarshallFile[[]struct{ Name, HTML string }]("fixtures/enrollment.json") + if err != nil { + t.Fatal(err) + } + scrapedAt := time.Date(2026, 8, 24, 12, 34, 56, 0, time.UTC) + expected := map[string]*schema.Enrollment{ + "closed": {Scraped_at: &scrapedAt, Status: "CLOSED/FULL", Available_seats: new(0), Enrolled_total: new(68), Waitlist: new(0)}, + "cross_listed": {Scraped_at: &scrapedAt, Status: "OPEN", Available_seats: new(10), Enrolled_total: new(14), Waitlist: new(0)}, + "over_enrolled": {Scraped_at: &scrapedAt, Status: "CLOSED/FULL", Available_seats: new(-15), Enrolled_total: new(57), Waitlist: new(0)}, + } + for _, fixture := range fixtures { + t.Run(fixture.Name, func(t *testing.T) { + doc, err := goquery.NewDocumentFromReader(strings.NewReader(fixture.HTML)) + if err != nil { + t.Fatal(err) + } + if diff := cmp.Diff(expected[fixture.Name], getEnrollment(getRowInfo(doc), &scrapedAt)); diff != "" { + t.Errorf("(-want +got):\n%s", diff) + } + }) + } + if got := getEnrollment(nil, &scrapedAt); got != nil { + t.Errorf("missing enrollment row = %v, want nil", got) + } +} + +func TestGetScrapedAt(t *testing.T) { + root := t.TempDir() + path := filepath.Join(root, "26f", "cp_cs", "section.html") + if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { + t.Fatal(err) + } + if got := getScrapedAt(path); got != nil { + t.Fatalf("missing timestamp file = %v, want nil", got) + } + if err := os.WriteFile(filepath.Join(root, "26f", "scraped_at.txt"), []byte("2026-08-24T12:34:56Z\n"), 0644); err != nil { + t.Fatal(err) + } + want := time.Date(2026, 8, 24, 12, 34, 56, 0, time.UTC) + if got := getScrapedAt(path); got == nil || !got.Equal(want) || got.Location() != time.UTC { + t.Errorf("scraped_at = %v, want UTC %v", got, want) + } +} + // TestGetInternalClassAndCourseNum checks parsing of internal course identifiers. func TestGetInternalClassAndCourseNum(t *testing.T) { t.Parallel() diff --git a/parser/testdata/case_000/section.json b/parser/testdata/case_000/section.json index adf994ce..de0b7c23 100644 --- a/parser/testdata/case_000/section.json +++ b/parser/testdata/case_000/section.json @@ -68,5 +68,12 @@ 0, 0 ], - "attributes": null + "attributes": null, + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 3, + "enrolled_total": 64, + "waitlist": 0 + } } diff --git a/parser/testdata/case_001/section.json b/parser/testdata/case_001/section.json index a5039fd4..c925f0e2 100644 --- a/parser/testdata/case_001/section.json +++ b/parser/testdata/case_001/section.json @@ -68,5 +68,12 @@ 0, 0 ], - "attributes": null + "attributes": null, + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 3, + "enrolled_total": 64, + "waitlist": 0 + } } diff --git a/parser/testdata/case_002/section.json b/parser/testdata/case_002/section.json index e28a111a..e60d5552 100644 --- a/parser/testdata/case_002/section.json +++ b/parser/testdata/case_002/section.json @@ -64,5 +64,12 @@ 0, 0 ], - "attributes": null + "attributes": null, + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "CLOSED/FULL", + "available_seats": 0, + "enrolled_total": 56, + "waitlist": 0 + } } diff --git a/parser/testdata/case_003/section.json b/parser/testdata/case_003/section.json index 93541b37..d2a2b469 100644 --- a/parser/testdata/case_003/section.json +++ b/parser/testdata/case_003/section.json @@ -34,5 +34,12 @@ "core_flags": [], "syllabus_uri": "https://dox.utdallas.edu/syl153921", "grade_distribution": [], - "attributes": null + "attributes": null, + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 9, + "enrolled_total": 1, + "waitlist": 0 + } } diff --git a/parser/testdata/case_004/section.json b/parser/testdata/case_004/section.json index bdc32178..ddf0bf67 100644 --- a/parser/testdata/case_004/section.json +++ b/parser/testdata/case_004/section.json @@ -32,5 +32,12 @@ "core_flags": [], "syllabus_uri": "", "grade_distribution": [], - "attributes": null + "attributes": null, + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 16, + "enrolled_total": 3, + "waitlist": 0 + } } diff --git a/parser/testdata/case_005/section.json b/parser/testdata/case_005/section.json index d89794bc..cbe8aa1c 100644 --- a/parser/testdata/case_005/section.json +++ b/parser/testdata/case_005/section.json @@ -47,5 +47,12 @@ "core_flags": [], "syllabus_uri": "", "grade_distribution": [], - "attributes": null + "attributes": null, + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 17, + "enrolled_total": 2, + "waitlist": 0 + } } diff --git a/parser/testdata/case_006/section.json b/parser/testdata/case_006/section.json index 6cce9059..0903a83d 100644 --- a/parser/testdata/case_006/section.json +++ b/parser/testdata/case_006/section.json @@ -57,5 +57,12 @@ 0, 0 ], - "attributes": null + "attributes": null, + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 15, + "enrolled_total": 33, + "waitlist": 0 + } } diff --git a/parser/testdata/scraped_at.txt b/parser/testdata/scraped_at.txt new file mode 100644 index 00000000..ad9af154 --- /dev/null +++ b/parser/testdata/scraped_at.txt @@ -0,0 +1 @@ +2025-01-25T12:30:01.123Z diff --git a/parser/testdata/sections.json b/parser/testdata/sections.json index 43a472cb..a5e79641 100644 --- a/parser/testdata/sections.json +++ b/parser/testdata/sections.json @@ -28,6 +28,13 @@ } ], "internal_class_number": "27706", + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 3, + "enrolled_total": 64, + "waitlist": 0 + }, "instruction_mode": "Face-to-Face", "meetings": [ { @@ -100,6 +107,13 @@ } ], "internal_class_number": "26595", + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 3, + "enrolled_total": 64, + "waitlist": 0 + }, "instruction_mode": "Face-to-Face", "meetings": [ { @@ -165,6 +179,13 @@ } ], "internal_class_number": "27195", + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "CLOSED/FULL", + "available_seats": 0, + "enrolled_total": 56, + "waitlist": 0 + }, "instruction_mode": "Face-to-Face", "meetings": [ { @@ -226,6 +247,13 @@ ], "teaching_assistants": [], "internal_class_number": "29611", + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 9, + "enrolled_total": 1, + "waitlist": 0 + }, "instruction_mode": "Face-to-Face", "meetings": [ { @@ -262,6 +290,13 @@ "professors": [], "teaching_assistants": [], "internal_class_number": "28551", + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 16, + "enrolled_total": 3, + "waitlist": 0 + }, "instruction_mode": "Face-to-Face", "meetings": [ { @@ -298,6 +333,13 @@ "professors": [], "teaching_assistants": [], "internal_class_number": "27906", + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 17, + "enrolled_total": 2, + "waitlist": 0 + }, "instruction_mode": "Face-to-Face", "meetings": [ { @@ -351,6 +393,13 @@ ], "teaching_assistants": [], "internal_class_number": "24043", + "latest_enrollment": { + "scraped_at": "2025-01-25T12:30:01.123Z", + "status": "OPEN", + "available_seats": 15, + "enrolled_total": 33, + "waitlist": 0 + }, "instruction_mode": "Face-to-Face", "meetings": [ { From 5b6363493a8282ec340159d944c7978d0a97647a Mon Sep 17 00:00:00 2001 From: Justin Schwerdtfeger Date: Sat, 14 Nov 2026 18:53:00 +0000 Subject: [PATCH 5/6] Move enrollment.json to testdata folder --- parser/parser_test.go | 13 +++++++------ parser/sectionParser_test.go | 2 +- parser/{fixtures => testdata}/enrollment.json | 0 3 files changed, 8 insertions(+), 7 deletions(-) rename parser/{fixtures => testdata}/enrollment.json (100%) diff --git a/parser/parser_test.go b/parser/parser_test.go index af0095b6..763cd157 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -132,14 +132,15 @@ func updateTestData() error { } defer os.RemoveAll(tempDir) - // Keep the shared scrape timestamp when regenerating the fixture tree. - timestampPath := filepath.Join("testdata", "scraped_at.txt") - if data, err := os.ReadFile(timestampPath); err == nil { - if err := os.WriteFile(filepath.Join(tempDir, "scraped_at.txt"), data, 0644); err != nil { + // Keep shared input files when regenerating testdata. + for _, name := range []string{"scraped_at.txt", "enrollment.json"} { + if data, err := os.ReadFile(filepath.Join("testdata", name)); err == nil { + if err := os.WriteFile(filepath.Join(tempDir, name), data, 0644); err != nil { + return err + } + } else if !os.IsNotExist(err) { return err } - } else if !os.IsNotExist(err) { - return err } GradeMap, err = loadGrades("../static-data/grades") diff --git a/parser/sectionParser_test.go b/parser/sectionParser_test.go index 215e0786..7106674c 100644 --- a/parser/sectionParser_test.go +++ b/parser/sectionParser_test.go @@ -14,7 +14,7 @@ import ( ) func TestGetEnrollment(t *testing.T) { - fixtures, err := unmarshallFile[[]struct{ Name, HTML string }]("fixtures/enrollment.json") + fixtures, err := unmarshallFile[[]struct{ Name, HTML string }]("testdata/enrollment.json") if err != nil { t.Fatal(err) } diff --git a/parser/fixtures/enrollment.json b/parser/testdata/enrollment.json similarity index 100% rename from parser/fixtures/enrollment.json rename to parser/testdata/enrollment.json From 0d50ee088414143b14f96a748c768a8fe9c985f1 Mon Sep 17 00:00:00 2001 From: Justin Schwerdtfeger Date: Sat, 14 Nov 2026 20:34:18 +0000 Subject: [PATCH 6/6] Update enrollment parser for latest API schema --- go.mod | 2 +- go.sum | 4 ++-- parser/sectionParser.go | 6 +++--- parser/sectionParser_test.go | 8 ++++---- parser/testdata/case_000/section.json | 2 +- parser/testdata/case_001/section.json | 2 +- parser/testdata/case_002/section.json | 2 +- parser/testdata/case_003/section.json | 2 +- parser/testdata/case_004/section.json | 2 +- parser/testdata/case_005/section.json | 2 +- parser/testdata/case_006/section.json | 2 +- parser/testdata/sections.json | 14 +++++++------- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 4c074f6d..eb6755cd 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.26.0 require ( github.com/PuerkitoBio/goquery v1.12.0 - github.com/UTDNebula/nebula-api v1.2.1-0.20261114001700-6f26423dffba + github.com/UTDNebula/nebula-api v1.2.1-0.20261114203121-26bbd574a0cf github.com/chromedp/cdproto v0.0.0-20260321001828-e3e3800016bc github.com/chromedp/chromedp v0.15.1 github.com/dongri/phonenumber v0.1.12 diff --git a/go.sum b/go.sum index c7b14fd3..2eda27fe 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapp github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.60.0/go.mod h1:SRAbhyZ4R4FagHMM9VtRgSY/lheRoht2fKelZXQUenk= github.com/PuerkitoBio/goquery v1.12.0 h1:pAcL4g3WRXekcB9AU/y1mbKez2dbY2AajVhtkO8RIBo= github.com/PuerkitoBio/goquery v1.12.0/go.mod h1:802ej+gV2y7bbIhOIoPY5sT183ZW0YFofScC4q/hIpQ= -github.com/UTDNebula/nebula-api v1.2.1-0.20261114001700-6f26423dffba h1:+PHtw9NHmgPUCbvWP0rv4aR7D+aPUcwR2lMZlwtizCw= -github.com/UTDNebula/nebula-api v1.2.1-0.20261114001700-6f26423dffba/go.mod h1:ckjoQ1cy323RvxYfGpmLFUYwb3pXSOvT7V0sCzPnFp4= +github.com/UTDNebula/nebula-api v1.2.1-0.20261114203121-26bbd574a0cf h1:q54Ub5hA4rU0ooWuVBOOFvWeiElJsnBFGELQT8UMh6E= +github.com/UTDNebula/nebula-api v1.2.1-0.20261114203121-26bbd574a0cf/go.mod h1:ckjoQ1cy323RvxYfGpmLFUYwb3pXSOvT7V0sCzPnFp4= github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= diff --git a/parser/sectionParser.go b/parser/sectionParser.go index 957f80bf..3aaf58ee 100644 --- a/parser/sectionParser.go +++ b/parser/sectionParser.go @@ -173,7 +173,7 @@ func getInstructionMode(classInfo map[string]string) string { // getEnrollment reads the labeled values in CourseBook's Status row. // A missing row or count stays absent rather than becoming a reported zero. -func getEnrollment(rowInfo map[string]*goquery.Selection, scrapedAt *time.Time) *schema.Enrollment { +func getEnrollment(rowInfo map[string]*goquery.Selection, scrapedAt *time.Time) *schema.SectionEnrollment { row, ok := rowInfo["Status:"] if !ok { return nil @@ -201,8 +201,8 @@ func getEnrollment(rowInfo map[string]*goquery.Selection, scrapedAt *time.Time) return &count } - enrollment := &schema.Enrollment{ - Scraped_at: scrapedAt, + enrollment := &schema.SectionEnrollment{ + Updated_at: scrapedAt, Status: strings.TrimSpace(values["Enrollment Status:"]), Available_seats: parseCount("Available Seats:", true), Waitlist: parseCount("Waitlist:", false), diff --git a/parser/sectionParser_test.go b/parser/sectionParser_test.go index 7106674c..e562fea8 100644 --- a/parser/sectionParser_test.go +++ b/parser/sectionParser_test.go @@ -19,10 +19,10 @@ func TestGetEnrollment(t *testing.T) { t.Fatal(err) } scrapedAt := time.Date(2026, 8, 24, 12, 34, 56, 0, time.UTC) - expected := map[string]*schema.Enrollment{ - "closed": {Scraped_at: &scrapedAt, Status: "CLOSED/FULL", Available_seats: new(0), Enrolled_total: new(68), Waitlist: new(0)}, - "cross_listed": {Scraped_at: &scrapedAt, Status: "OPEN", Available_seats: new(10), Enrolled_total: new(14), Waitlist: new(0)}, - "over_enrolled": {Scraped_at: &scrapedAt, Status: "CLOSED/FULL", Available_seats: new(-15), Enrolled_total: new(57), Waitlist: new(0)}, + expected := map[string]*schema.SectionEnrollment{ + "closed": {Updated_at: &scrapedAt, Status: "CLOSED/FULL", Available_seats: new(0), Enrolled_total: new(68), Waitlist: new(0)}, + "cross_listed": {Updated_at: &scrapedAt, Status: "OPEN", Available_seats: new(10), Enrolled_total: new(14), Waitlist: new(0)}, + "over_enrolled": {Updated_at: &scrapedAt, Status: "CLOSED/FULL", Available_seats: new(-15), Enrolled_total: new(57), Waitlist: new(0)}, } for _, fixture := range fixtures { t.Run(fixture.Name, func(t *testing.T) { diff --git a/parser/testdata/case_000/section.json b/parser/testdata/case_000/section.json index de0b7c23..c86d1f21 100644 --- a/parser/testdata/case_000/section.json +++ b/parser/testdata/case_000/section.json @@ -70,7 +70,7 @@ ], "attributes": null, "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 3, "enrolled_total": 64, diff --git a/parser/testdata/case_001/section.json b/parser/testdata/case_001/section.json index c925f0e2..05c1d317 100644 --- a/parser/testdata/case_001/section.json +++ b/parser/testdata/case_001/section.json @@ -70,7 +70,7 @@ ], "attributes": null, "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 3, "enrolled_total": 64, diff --git a/parser/testdata/case_002/section.json b/parser/testdata/case_002/section.json index e60d5552..e870b663 100644 --- a/parser/testdata/case_002/section.json +++ b/parser/testdata/case_002/section.json @@ -66,7 +66,7 @@ ], "attributes": null, "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "CLOSED/FULL", "available_seats": 0, "enrolled_total": 56, diff --git a/parser/testdata/case_003/section.json b/parser/testdata/case_003/section.json index d2a2b469..7a59494b 100644 --- a/parser/testdata/case_003/section.json +++ b/parser/testdata/case_003/section.json @@ -36,7 +36,7 @@ "grade_distribution": [], "attributes": null, "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 9, "enrolled_total": 1, diff --git a/parser/testdata/case_004/section.json b/parser/testdata/case_004/section.json index ddf0bf67..3a949047 100644 --- a/parser/testdata/case_004/section.json +++ b/parser/testdata/case_004/section.json @@ -34,7 +34,7 @@ "grade_distribution": [], "attributes": null, "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 16, "enrolled_total": 3, diff --git a/parser/testdata/case_005/section.json b/parser/testdata/case_005/section.json index cbe8aa1c..08d7c2db 100644 --- a/parser/testdata/case_005/section.json +++ b/parser/testdata/case_005/section.json @@ -49,7 +49,7 @@ "grade_distribution": [], "attributes": null, "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 17, "enrolled_total": 2, diff --git a/parser/testdata/case_006/section.json b/parser/testdata/case_006/section.json index 0903a83d..76f31e5c 100644 --- a/parser/testdata/case_006/section.json +++ b/parser/testdata/case_006/section.json @@ -59,7 +59,7 @@ ], "attributes": null, "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 15, "enrolled_total": 33, diff --git a/parser/testdata/sections.json b/parser/testdata/sections.json index a5e79641..041c74bc 100644 --- a/parser/testdata/sections.json +++ b/parser/testdata/sections.json @@ -29,7 +29,7 @@ ], "internal_class_number": "27706", "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 3, "enrolled_total": 64, @@ -108,7 +108,7 @@ ], "internal_class_number": "26595", "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 3, "enrolled_total": 64, @@ -180,7 +180,7 @@ ], "internal_class_number": "27195", "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "CLOSED/FULL", "available_seats": 0, "enrolled_total": 56, @@ -248,7 +248,7 @@ "teaching_assistants": [], "internal_class_number": "29611", "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 9, "enrolled_total": 1, @@ -291,7 +291,7 @@ "teaching_assistants": [], "internal_class_number": "28551", "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 16, "enrolled_total": 3, @@ -334,7 +334,7 @@ "teaching_assistants": [], "internal_class_number": "27906", "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 17, "enrolled_total": 2, @@ -394,7 +394,7 @@ "teaching_assistants": [], "internal_class_number": "24043", "latest_enrollment": { - "scraped_at": "2025-01-25T12:30:01.123Z", + "updated_at": "2025-01-25T12:30:01.123Z", "status": "OPEN", "available_seats": 15, "enrolled_total": 33,