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 /aplus.go | |
| parent | e9c76998dc146ebc5f22100c972b52c70a51899d (diff) | |
start working on submitting course without user-provided course code
Diffstat (limited to 'aplus.go')
| -rw-r--r-- | aplus.go | 28 |
1 files changed, 27 insertions, 1 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 | } | ||
