commit cbcc7631a4df81682db46fd6ea7f581f13cb21ea
parent 1179315d30b3c9bb5962961c158c325ba1eb3243
Author: vin <git@vineetk.net>
Date: Fri, 12 Jan 2024 17:22:35 -0500
send attendance code to all current courses when course not specified
Diffstat:
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git 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
@@ -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