diff options
| -rw-r--r-- | aplus.go | 8 | ||||
| -rw-r--r-- | canvas.go | 3 |
2 files changed, 7 insertions, 4 deletions
| @@ -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 | ||
| 14 | func submit_code(course_code int, attendance_code string) bool { | 13 | func 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 | } |
| @@ -54,6 +54,7 @@ func get_courses(token string, link string, client http.Client) []CanvasCourse { | |||
| 54 | 54 | ||
| 55 | func init_aplus_toolid(course_id int) error { | 55 | func 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 |
