aplus

A+Attendance CLI utility via Instructure Canvas
Log | Files | Refs | README | LICENSE

commit de8ed98b4c43c2486d72eb6b5a9301f42d2a61d6
parent e9c76998dc146ebc5f22100c972b52c70a51899d
Author: vin <git@vineetk.net>
Date:   Thu, 11 Jan 2024 18:36:22 -0500

start working on submitting course without user-provided course code

Diffstat:
Maplus.go | 28+++++++++++++++++++++++++++-
Mcanvas.go | 10++++++++--
Mmain.go | 9++++-----
3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/aplus.go b/aplus.go @@ -11,17 +11,27 @@ import ( "strings" ) -func submit_code(course_code int, attendance_code string) { +func submit_code(course_code int, attendance_code string) bool { cur_body := launch_aplus(course_code) if verbose { fmt.Printf("%s", cur_body) } + if strings.Contains(cur_body, "Student not known") { + fmt.Println("Student not known. This course must first be visited by an instructor for students to have access.") + return false + } + current_url := fmt.Sprintf("%s/student/", base_aplus_link) // the links to submit the code for a class is under the dayPanel div daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") + if !strings.Contains(cur_body[daypanel_start:], "<a href=\"./?module") { + fmt.Println("No code submitted. Did the professor generate the code or is the class in session?") + return false + } + // link_start - link_end is to extract the URL // TODO: make this more elegant to allow multiple of these links // (maybe use an html parser) @@ -62,6 +72,8 @@ func submit_code(course_code int, attendance_code string) { } else if strings.Index(string(body), "ctl02_codeSuccessMessage") != -1 { fmt.Println("Code successfully recorded") } + + return true } func launch_aplus(course_code int) string { @@ -148,3 +160,17 @@ func extract_attribute(input string, attribute string) string { return input[start : start+end] } + +func submit_code_sans_course(attendance_code string) { + courses := list_all_courses(true) + + for _, course := range courses { + fmt.Println("Checking with course", course.ID%10000) + if submit_code(int(course.ID%10000), attendance_code) == true { + fmt.Println("Submitted code to course", course.ID%10000) + return + } + } + + fmt.Println("Could not submit code %s to any course\n", attendance_code) +} diff --git a/canvas.go b/canvas.go @@ -83,9 +83,15 @@ func list_all_courses() { canvas_courses := get_courses(token, all_courses, client) - for _, course := range canvas_courses { - fmt.Printf("%d, %s\n", course.ID%10000, course.Name) + if !onlyreturn { + + for _, course := range canvas_courses { + fmt.Printf("%d, %s\n", course.ID%10000, course.Name) + } + } + + return canvas_courses } func list_favorite_courses() { diff --git a/main.go b/main.go @@ -54,7 +54,7 @@ func main() { } if listall { - list_all_courses() + _ = list_all_courses(false) os.Exit(0) } @@ -71,10 +71,6 @@ func main() { if len(code) == 5 && course != -1 { fmt.Printf("%d %s\n", course, code) submit_code(course, code) - } else if code != "" && course == -1 { - fmt.Println("Course code not provided") - usage() - os.Exit(1) } else if code == "" && course != -1 { fmt.Println("Attendance code not provided") usage() @@ -83,5 +79,8 @@ func main() { fmt.Println("Attendance code must be 5 characters long") usage() os.Exit(1) + } else if len(code) == 5 && course == -1 { + fmt.Println("Checking which course to send the code to") + submit_code_sans_course(code) } }