diff options
| author | vin <git@vineetk.net> | 2024-01-11 18:36:22 -0500 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2024-01-11 22:55:43 -0500 |
| commit | de8ed98b4c43c2486d72eb6b5a9301f42d2a61d6 (patch) | |
| tree | 5fb2ac810420ab6c994829bb1487769fa796dac0 | |
| parent | e9c76998dc146ebc5f22100c972b52c70a51899d (diff) | |
start working on submitting course without user-provided course code
| -rw-r--r-- | aplus.go | 28 | ||||
| -rw-r--r-- | canvas.go | 10 | ||||
| -rw-r--r-- | main.go | 9 |
3 files changed, 39 insertions, 8 deletions
| @@ -11,17 +11,27 @@ import ( | |||
| 11 | "strings" | 11 | "strings" |
| 12 | ) | 12 | ) |
| 13 | 13 | ||
| 14 | func submit_code(course_code int, attendance_code string) { | 14 | func submit_code(course_code int, attendance_code string) bool { |
| 15 | cur_body := launch_aplus(course_code) | 15 | cur_body := launch_aplus(course_code) |
| 16 | 16 | ||
| 17 | if verbose { | 17 | if verbose { |
| 18 | fmt.Printf("%s", cur_body) | 18 | fmt.Printf("%s", cur_body) |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | if strings.Contains(cur_body, "Student not known") { | ||
| 22 | fmt.Println("Student not known. This course must first be visited by an instructor for students to have access.") | ||
| 23 | return false | ||
| 24 | } | ||
| 25 | |||
| 21 | current_url := fmt.Sprintf("%s/student/", base_aplus_link) | 26 | current_url := fmt.Sprintf("%s/student/", base_aplus_link) |
| 22 | // the links to submit the code for a class is under the dayPanel div | 27 | // the links to submit the code for a class is under the dayPanel div |
| 23 | daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") | 28 | daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") |
| 24 | 29 | ||
| 30 | if !strings.Contains(cur_body[daypanel_start:], "<a href=\"./?module") { | ||
| 31 | fmt.Println("No code submitted. Did the professor generate the code or is the class in session?") | ||
| 32 | return false | ||
| 33 | } | ||
| 34 | |||
| 25 | // link_start - link_end is to extract the URL | 35 | // link_start - link_end is to extract the URL |
| 26 | // TODO: make this more elegant to allow multiple of these links | 36 | // TODO: make this more elegant to allow multiple of these links |
| 27 | // (maybe use an html parser) | 37 | // (maybe use an html parser) |
| @@ -62,6 +72,8 @@ func submit_code(course_code int, attendance_code string) { | |||
| 62 | } else if strings.Index(string(body), "ctl02_codeSuccessMessage") != -1 { | 72 | } else if strings.Index(string(body), "ctl02_codeSuccessMessage") != -1 { |
| 63 | fmt.Println("Code successfully recorded") | 73 | fmt.Println("Code successfully recorded") |
| 64 | } | 74 | } |
| 75 | |||
| 76 | return true | ||
| 65 | } | 77 | } |
| 66 | 78 | ||
| 67 | func launch_aplus(course_code int) string { | 79 | func launch_aplus(course_code int) string { |
| @@ -148,3 +160,17 @@ func extract_attribute(input string, attribute string) string { | |||
| 148 | 160 | ||
| 149 | return input[start : start+end] | 161 | return input[start : start+end] |
| 150 | } | 162 | } |
| 163 | |||
| 164 | func submit_code_sans_course(attendance_code string) { | ||
| 165 | courses := list_all_courses(true) | ||
| 166 | |||
| 167 | for _, course := range courses { | ||
| 168 | fmt.Println("Checking with course", course.ID%10000) | ||
| 169 | if submit_code(int(course.ID%10000), attendance_code) == true { | ||
| 170 | fmt.Println("Submitted code to course", course.ID%10000) | ||
| 171 | return | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | fmt.Println("Could not submit code %s to any course\n", attendance_code) | ||
| 176 | } | ||
| @@ -83,9 +83,15 @@ func list_all_courses() { | |||
| 83 | 83 | ||
| 84 | canvas_courses := get_courses(token, all_courses, client) | 84 | canvas_courses := get_courses(token, all_courses, client) |
| 85 | 85 | ||
| 86 | for _, course := range canvas_courses { | 86 | if !onlyreturn { |
| 87 | fmt.Printf("%d, %s\n", course.ID%10000, course.Name) | 87 | |
| 88 | for _, course := range canvas_courses { | ||
| 89 | fmt.Printf("%d, %s\n", course.ID%10000, course.Name) | ||
| 90 | } | ||
| 91 | |||
| 88 | } | 92 | } |
| 93 | |||
| 94 | return canvas_courses | ||
| 89 | } | 95 | } |
| 90 | 96 | ||
| 91 | func list_favorite_courses() { | 97 | func list_favorite_courses() { |
| @@ -54,7 +54,7 @@ func main() { | |||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | if listall { | 56 | if listall { |
| 57 | list_all_courses() | 57 | _ = list_all_courses(false) |
| 58 | os.Exit(0) | 58 | os.Exit(0) |
| 59 | } | 59 | } |
| 60 | 60 | ||
| @@ -71,10 +71,6 @@ func main() { | |||
| 71 | if len(code) == 5 && course != -1 { | 71 | if len(code) == 5 && course != -1 { |
| 72 | fmt.Printf("%d %s\n", course, code) | 72 | fmt.Printf("%d %s\n", course, code) |
| 73 | submit_code(course, code) | 73 | submit_code(course, code) |
| 74 | } else if code != "" && course == -1 { | ||
| 75 | fmt.Println("Course code not provided") | ||
| 76 | usage() | ||
| 77 | os.Exit(1) | ||
| 78 | } else if code == "" && course != -1 { | 74 | } else if code == "" && course != -1 { |
| 79 | fmt.Println("Attendance code not provided") | 75 | fmt.Println("Attendance code not provided") |
| 80 | usage() | 76 | usage() |
| @@ -83,5 +79,8 @@ func main() { | |||
| 83 | fmt.Println("Attendance code must be 5 characters long") | 79 | fmt.Println("Attendance code must be 5 characters long") |
| 84 | usage() | 80 | usage() |
| 85 | os.Exit(1) | 81 | os.Exit(1) |
| 82 | } else if len(code) == 5 && course == -1 { | ||
| 83 | fmt.Println("Checking which course to send the code to") | ||
| 84 | submit_code_sans_course(code) | ||
| 86 | } | 85 | } |
| 87 | } | 86 | } |
