diff options
| -rw-r--r-- | README.md | 15 | ||||
| -rw-r--r-- | aplus.go | 11 | ||||
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | main.go | 25 |
4 files changed, 30 insertions, 23 deletions
| @@ -1,23 +1,16 @@ | |||
| 1 | # aplus | 1 | # aplus command line utility |
| 2 | 2 | ||
| 3 | This is an aplus cli utility created for students at Florida Polytechnic University to submit their aplus codes through the CLI. | 3 | This is an cli utility initially created for students at Florida Polytechnic University to submit their aplus codes. |
| 4 | In time, we intend to generalize this utility to all universities. | 4 | In time, we intend to generalize this utility to all universities. |
| 5 | In the meantime however, any students from other universities wishing to use the utility may change the base_link and external_tools_code (you see this in the URL when you navigate to Aplus attendance within your course) variables. | 5 | In the meantime however, any students from other universities wishing to use the utility may change the base_link and external_tools_code (you see this in the URL when you navigate to Aplus attendance within your course) variables. |
| 6 | 6 | ||
| 7 | ## Usage | 7 | ## Usage |
| 8 | 8 | ||
| 9 | ### List all courses and canvas course codes | 9 | ### List all courses and canvas course codes |
| 10 | aplus | 10 | aplus --list-all |
| 11 | aplus --list-courses | ||
| 12 | aplus -l | ||
| 13 | 11 | ||
| 14 | ### List favorite courses and canvas course codes | 12 | ### List favorite courses and canvas course codes |
| 15 | aplus --list-favorites | 13 | aplus --list-favorites |
| 16 | 14 | ||
| 17 | ### Enter code immediately for an active code | ||
| 18 | aplus -c <code> | ||
| 19 | aplus --code <code> | ||
| 20 | |||
| 21 | ### Enter code for a specified course | 15 | ### Enter code for a specified course |
| 22 | aplus -c <code> --course <course_code> | 16 | aplus --code <code> --course <canvas_course_number> \ No newline at end of file |
| 23 | aplus --code <code> --course <course_code> \ No newline at end of file | ||
| @@ -12,6 +12,9 @@ import ( | |||
| 12 | 12 | ||
| 13 | func submit_code(course_code int, attendance_code string) { | 13 | func submit_code(course_code int, attendance_code string) { |
| 14 | cur_body := launch_aplus(course_code) | 14 | cur_body := launch_aplus(course_code) |
| 15 | |||
| 16 | fmt.Printf("%s", cur_body) | ||
| 17 | |||
| 15 | current_url := fmt.Sprintf("%s/student/", base_aplus_link) | 18 | current_url := fmt.Sprintf("%s/student/", base_aplus_link) |
| 16 | // the links to submit the code for a class is under the dayPanel div | 19 | // the links to submit the code for a class is under the dayPanel div |
| 17 | daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") | 20 | daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") |
| @@ -37,21 +40,13 @@ func submit_code(course_code int, attendance_code string) { | |||
| 37 | resp, _ := client.Get(link_url) | 40 | resp, _ := client.Get(link_url) |
| 38 | body, _ := io.ReadAll(resp.Body) | 41 | body, _ := io.ReadAll(resp.Body) |
| 39 | 42 | ||
| 40 | fmt.Println(string(body)) | ||
| 41 | |||
| 42 | form_str := get_form_from_request_body(body) | 43 | form_str := get_form_from_request_body(body) |
| 43 | form_values := parse_form(form_str) | 44 | form_values := parse_form(form_str) |
| 44 | form_values["ctl01$sessionCode"][0] = attendance_code | 45 | form_values["ctl01$sessionCode"][0] = attendance_code |
| 45 | 46 | ||
| 46 | //fmt.Println(form_str) | ||
| 47 | //fmt.Println(form_values) | ||
| 48 | |||
| 49 | resp, _ = client.PostForm(link_url, form_values) | 47 | resp, _ = client.PostForm(link_url, form_values) |
| 50 | body, _ = io.ReadAll(resp.Body) | 48 | body, _ = io.ReadAll(resp.Body) |
| 51 | 49 | ||
| 52 | fmt.Println(string(body)) | ||
| 53 | fmt.Println(resp) | ||
| 54 | |||
| 55 | if strings.Index(string(body), "ctl01_errorMessage") != -1 { | 50 | if strings.Index(string(body), "ctl01_errorMessage") != -1 { |
| 56 | errormsg_start := strings.Index(string(body), "ctl01_errorMessage") | 51 | errormsg_start := strings.Index(string(body), "ctl01_errorMessage") |
| 57 | errormsg_start += strings.Index(string(body)[errormsg_start:], "Text\">") | 52 | errormsg_start += strings.Index(string(body)[errormsg_start:], "Text\">") |
| @@ -2,4 +2,4 @@ module codeberg.org/flpolyaplus/aplus | |||
| 2 | 2 | ||
| 3 | go 1.21.3 | 3 | go 1.21.3 |
| 4 | 4 | ||
| 5 | require golang.org/x/net v0.18.0 // indirect | 5 | require golang.org/x/net v0.18.0 |
| @@ -1,6 +1,8 @@ | |||
| 1 | package main | 1 | package main |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "flag" | ||
| 5 | "fmt" | ||
| 4 | "net/http" | 6 | "net/http" |
| 5 | ) | 7 | ) |
| 6 | 8 | ||
| @@ -13,8 +15,25 @@ var client http.Client | |||
| 13 | func main() { | 15 | func main() { |
| 14 | initialize() | 16 | initialize() |
| 15 | 17 | ||
| 16 | course_code := 7326 | 18 | code := flag.String("code", "", "Code to enter") |
| 17 | submit_code(course_code, "A1B2C") | 19 | course := flag.Int("course", -1, "Canvas course number") |
| 20 | list_all := flag.Bool("list-all", false, "List all courses") | ||
| 21 | list_favorites := flag.Bool("list-favorites", false, "List favorite courses") | ||
| 18 | 22 | ||
| 19 | // enter_code() | 23 | flag.Parse() |
| 24 | |||
| 25 | if *list_all { | ||
| 26 | list_all_courses() | ||
| 27 | } | ||
| 28 | |||
| 29 | if *list_favorites { | ||
| 30 | list_favorite_courses() | ||
| 31 | } | ||
| 32 | |||
| 33 | if *code != "" && *course != -1 { | ||
| 34 | fmt.Printf("%d %s", *course, *code) | ||
| 35 | submit_code(*course, *code) | ||
| 36 | } | ||
| 37 | |||
| 38 | submit_code(7329, "asdkl") | ||
| 20 | } | 39 | } |
