summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2024-01-12 17:22:35 -0500
committervin <git@vineetk.net>2024-01-12 17:24:09 -0500
commitcbcc7631a4df81682db46fd6ea7f581f13cb21ea (patch)
treeb18c8bd1c1a1358bbd0b2e05776f492323e627ba
parent1179315d30b3c9bb5962961c158c325ba1eb3243 (diff)
send attendance code to all current courses when course not specified
-rw-r--r--aplus.go8
-rw-r--r--canvas.go3
2 files changed, 7 insertions, 4 deletions
diff --git a/aplus.go b/aplus.go
index 29d5033..2e2ab0a 100644
--- a/aplus.go
+++ b/aplus.go
@@ -7,12 +7,14 @@ import (
7 "io" 7 "io"
8 "net/http" 8 "net/http"
9 "net/url" 9 "net/url"
10 "os"
11 "strings" 10 "strings"
12) 11)
13 12
14func submit_code(course_code int, attendance_code string) bool { 13func submit_code(course_code int, attendance_code string) bool {
15 cur_body := launch_aplus(course_code) 14 cur_body := launch_aplus(course_code)
15 if cur_body == "" {
16 return false
17 }
16 18
17 if verbose { 19 if verbose {
18 fmt.Printf("%s", cur_body) 20 fmt.Printf("%s", cur_body)
@@ -81,7 +83,7 @@ func launch_aplus(course_code int) string {
81 if err != nil { 83 if err != nil {
82 fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.") 84 fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.")
83 fmt.Printf("Error: %s\n", err) 85 fmt.Printf("Error: %s\n", err)
84 os.Exit(1) 86 return ""
85 } 87 }
86 88
87 aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s", 89 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) {
172 } 174 }
173 } 175 }
174 176
175 fmt.Println("Could not submit code %s to any course\n", attendance_code) 177 fmt.Println("Could not submit code", attendance_code, "to any course")
176} 178}
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 {
54 54
55func init_aplus_toolid(course_id int) error { 55func init_aplus_toolid(course_id int) error {
56 link := fmt.Sprintf("%s/courses/%d/external_tools?access_token=%s&search_term=aplus&include_parents=true", base_link, course_id, token) 56 link := fmt.Sprintf("%s/courses/%d/external_tools?access_token=%s&search_term=aplus&include_parents=true", base_link, course_id, token)
57
57 resp, err := client.Get(link) 58 resp, err := client.Get(link)
58 if err != nil { 59 if err != nil {
59 return err 60 return err
@@ -68,7 +69,7 @@ func init_aplus_toolid(course_id int) error {
68 } 69 }
69 70
70 for _, tool := range external_tools { 71 for _, tool := range external_tools {
71 if strings.Contains(tool.URL, ".aplusattendance.com/") && base_aplus_link == "" { 72 if strings.Contains(tool.URL, ".aplusattendance.com/") {
72 base_aplus_link = tool.URL 73 base_aplus_link = tool.URL
73 external_tools_code = tool.ID 74 external_tools_code = tool.ID
74 return nil 75 return nil