diff --git a/aplus.go b/aplus.go index 29d5033..2e2ab0a 100644 --- a/aplus.go +++ b/aplus.go @@ -7,12 +7,14 @@ import ( "io" "net/http" "net/url" - "os" "strings" ) func submit_code(course_code int, attendance_code string) bool { cur_body := launch_aplus(course_code) + if cur_body == "" { + return false + } if verbose { fmt.Printf("%s", cur_body) @@ -81,7 +83,7 @@ func launch_aplus(course_code int) string { if err != nil { fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.") fmt.Printf("Error: %s\n", err) - os.Exit(1) + return "" } aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s", @@ -172,5 +174,5 @@ func submit_code_sans_course(attendance_code string) { } } - fmt.Println("Could not submit code %s to any course\n", attendance_code) + fmt.Println("Could not submit code", attendance_code, "to any course") } diff --git a/canvas.go b/canvas.go index 1cf84fe..356a3a2 100644 --- a/canvas.go +++ b/canvas.go @@ -54,6 +54,7 @@ func get_courses(token string, link string, client http.Client) []CanvasCourse { func init_aplus_toolid(course_id int) error { link := fmt.Sprintf("%s/courses/%d/external_tools?access_token=%s&search_term=aplus&include_parents=true", base_link, course_id, token) + resp, err := client.Get(link) if err != nil { return err @@ -68,7 +69,7 @@ func init_aplus_toolid(course_id int) error { } for _, tool := range external_tools { - if strings.Contains(tool.URL, ".aplusattendance.com/") && base_aplus_link == "" { + if strings.Contains(tool.URL, ".aplusattendance.com/") { base_aplus_link = tool.URL external_tools_code = tool.ID return nil