Skip to content

Commit ad80e28

Browse files
authored
Merge branch 'develop' into resume
2 parents 3ab9e5e + 11e9164 commit ad80e28

File tree

5 files changed

+38
-34
lines changed

5 files changed

+38
-34
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Set up Go
2323
uses: actions/setup-go@v5
2424
with:
25-
go-version: '1.23'
25+
go-version: '1.24'
2626

2727
- name: Setup
2828
run: make setup
@@ -43,7 +43,7 @@ jobs:
4343
- name: Set up Go
4444
uses: actions/setup-go@v4
4545
with:
46-
go-version: '1.23'
46+
go-version: '1.24'
4747

4848
- name: Setup
4949
run: .\build.bat setup

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23 AS builder
1+
FROM golang:1.24 AS builder
22

33
WORKDIR /app
44
COPY . .

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/UTDNebula/api-tools
22

3-
go 1.23.0
3+
go 1.24
44

55
require (
66
github.com/PuerkitoBio/goquery v1.8.1

parser/validator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ func testDuplicatePass(objType string, ix1 int, ix2 int, t *testing.T) {
342342
defer func() {
343343
logOutput := logBuffer.String()
344344
if logOutput != "" {
345-
t.Errorf("Expected nothing in log for " + objType)
345+
t.Errorf("Expected nothing in log for %s", objType)
346346
}
347347
if r := recover(); r != nil {
348-
t.Errorf("The function panic unexpectedly for " + objType)
348+
t.Errorf("The function panic unexpectedly for %s", objType)
349349
}
350350
}()
351351

utils/methods.go

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/chromedp/cdproto/cdp"
2222
"github.com/chromedp/cdproto/network"
23+
"github.com/chromedp/cdproto/runtime"
2324
"github.com/chromedp/chromedp"
2425
)
2526

@@ -38,7 +39,14 @@ func GetEnv(name string) (string, error) {
3839
func InitChromeDp() (chromedpCtx context.Context, cancelFnc context.CancelFunc) {
3940
log.Printf("Initializing chromedp...")
4041
if Headless {
41-
chromedpCtx, cancelFnc = chromedp.NewContext(context.Background())
42+
opts := append(chromedp.DefaultExecAllocatorOptions[:],
43+
chromedp.Flag("headless", true),
44+
chromedp.Flag("no-sandbox", true),
45+
chromedp.Flag("disable-dev-shm-usage", true),
46+
chromedp.Flag("disable-gpu", true),
47+
)
48+
allocCtx, _ := chromedp.NewExecAllocator(context.Background(), opts...)
49+
chromedpCtx, cancelFnc = chromedp.NewContext(allocCtx)
4250
} else {
4351
allocCtx, _ := chromedp.NewExecAllocator(context.Background())
4452
chromedpCtx, cancelFnc = chromedp.NewContext(allocCtx)
@@ -93,6 +101,9 @@ func RefreshToken(chromedpCtx context.Context) map[string][]string {
93101
chromedp.Navigate(`https://coursebook.utdallas.edu/`),
94102
chromedp.ActionFunc(func(ctx context.Context) error {
95103
cookies, err := network.GetCookies().Do(ctx)
104+
if err != nil {
105+
return err
106+
}
96107
cookieStrs = make([]string, len(cookies))
97108
gotToken := false
98109
for i, cookie := range cookies {
@@ -105,7 +116,7 @@ func RefreshToken(chromedpCtx context.Context) map[string][]string {
105116
if !gotToken {
106117
return errors.New("failed to get a new token")
107118
}
108-
return err
119+
return nil
109120
}),
110121
)
111122
if r != nil && r.Status != 200 {
@@ -164,10 +175,12 @@ func RefreshAstraToken(chromedpCtx context.Context) map[string][]string {
164175

165176
// Save all cookies to string
166177
cookieStr := ""
167-
_, err = chromedp.RunResponse(chromedpCtx,
168-
chromedp.WaitVisible(`body`, chromedp.ByQuery),
178+
err = chromedp.Run(chromedpCtx,
169179
chromedp.ActionFunc(func(ctx context.Context) error {
170180
cookies, err := network.GetCookies().Do(ctx)
181+
if err != nil {
182+
return err
183+
}
171184
gotToken := false
172185
for _, cookie := range cookies {
173186
cookieStr = fmt.Sprintf("%s%s=%s; ", cookieStr, cookie.Name, cookie.Value)
@@ -179,7 +192,7 @@ func RefreshAstraToken(chromedpCtx context.Context) map[string][]string {
179192
if !gotToken {
180193
return errors.New("failed to get a new token")
181194
}
182-
return err
195+
return nil
183196
}),
184197
)
185198
if err != nil {
@@ -278,42 +291,33 @@ func Retry(action func() error, maxRetries int, retryCallback func(numRetries in
278291

279292
// Get all the available course prefixes
280293
func GetCoursePrefixes(chromedpCtx context.Context) []string {
281-
// Refresh the token
294+
// Might need to refresh the token every time we get new course prefixes in the future
282295
// refreshToken(chromedpCtx)
283296

284-
log.Printf("Finding course prefix nodes...")
285-
286297
var coursePrefixes []string
287-
var coursePrefixNodes []*cdp.Node
298+
log.Println("Finding course prefixes...")
288299

289300
// Get option elements for course prefix dropdown
290-
err := chromedp.Run(chromedpCtx,
301+
_, err := chromedp.RunResponse(chromedpCtx,
291302
chromedp.Navigate("https://coursebook.utdallas.edu"),
292-
chromedp.Nodes("select#combobox_cp option", &coursePrefixNodes, chromedp.ByQueryAll),
303+
chromedp.QueryAfter("select#combobox_cp option",
304+
func(ctx context.Context, _ runtime.ExecutionContextID, nodes ...*cdp.Node) error {
305+
for _, node := range nodes[1:] {
306+
coursePrefixes = append(coursePrefixes, node.AttributeValue("value"))
307+
}
308+
return nil
309+
},
310+
),
293311
)
294-
295312
if err != nil {
296313
log.Panic(err)
297314
}
298-
299-
log.Println("Found the course prefix nodes!")
300-
301-
log.Println("Finding course prefixes...")
302-
303-
// Remove the first option due to it being empty
304-
coursePrefixNodes = coursePrefixNodes[1:]
305-
306-
// Get the value of each option and append to coursePrefixes
307-
for _, node := range coursePrefixNodes {
308-
coursePrefixes = append(coursePrefixes, node.AttributeValue("value"))
309-
}
310-
311-
log.Println("Found the course prefixes!")
312-
315+
log.Printf("Found the %d course prefixes!", len(coursePrefixes))
313316
return coursePrefixes
314317
}
315318

316-
func ConvertFromInterface[T string | float64](value interface{}) *T {
319+
// Convert the value of any type to either string or float64
320+
func ConvertFromInterface[T string | float64](value any) *T {
317321
if parsed, ok := value.(T); ok {
318322
return &parsed
319323
}

0 commit comments

Comments
 (0)