send attendance code to all current courses when course not specified

This commit is contained in:
Vineet K 2024-01-12 17:22:35 -05:00
parent 1179315d30
commit cbcc7631a4
2 changed files with 7 additions and 4 deletions

View File

@ -7,12 +7,14 @@ import (
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"os"
"strings" "strings"
) )
func submit_code(course_code int, attendance_code string) bool { func submit_code(course_code int, attendance_code string) bool {
cur_body := launch_aplus(course_code) cur_body := launch_aplus(course_code)
if cur_body == "" {
return false
}
if verbose { if verbose {
fmt.Printf("%s", cur_body) fmt.Printf("%s", cur_body)
@ -81,7 +83,7 @@ func launch_aplus(course_code int) string {
if err != nil { if err != nil {
fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.") fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.")
fmt.Printf("Error: %s\n", err) 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", 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")
} }

View File

@ -54,6 +54,7 @@ func get_courses(token string, link string, client http.Client) []CanvasCourse {
func init_aplus_toolid(course_id int) error { 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) 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) resp, err := client.Get(link)
if err != nil { if err != nil {
return err return err
@ -68,7 +69,7 @@ func init_aplus_toolid(course_id int) error {
} }
for _, tool := range external_tools { 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 base_aplus_link = tool.URL
external_tools_code = tool.ID external_tools_code = tool.ID
return nil return nil