diff options
| author | Juan Roig <jaroig@outlook.com> | 2023-11-14 18:04:29 -0500 |
|---|---|---|
| committer | Juan Roig <jaroig@outlook.com> | 2023-11-14 18:04:29 -0500 |
| commit | 329f8dfe029025d591cf3e111dc842a7f4c2a43f (patch) | |
| tree | d4beebd24a00ed8503916c5b0f68840191d177fc /aplus.go | |
| parent | 7b613b030da2432830a9f00bfc6aeb9e59bcd728 (diff) | |
Reorganization
Diffstat (limited to 'aplus.go')
| -rw-r--r-- | aplus.go | 61 |
1 files changed, 30 insertions, 31 deletions
| @@ -10,37 +10,9 @@ import ( | |||
| 10 | "strings" | 10 | "strings" |
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | func launch_aplus(course_code int, attendance_code string) { | 13 | func submit_code(course_code int, attendance_code string) { |
| 14 | aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s", | 14 | cur_body := launch_aplus(course_code) |
| 15 | base_link, course_code, external_tools_code, token) | 15 | current_url := fmt.Sprintf("%s/student/", base_aplus_link) |
| 16 | aplus := get_aplus(token, aplus_link, client) | ||
| 17 | |||
| 18 | resp, _ := client.Get(aplus) | ||
| 19 | body, _ := io.ReadAll(resp.Body) | ||
| 20 | |||
| 21 | form_str := get_form_from_request_body(body) | ||
| 22 | form_values := parse_form(form_str) | ||
| 23 | |||
| 24 | resp, _ = client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values) | ||
| 25 | body, _ = io.ReadAll(resp.Body) | ||
| 26 | |||
| 27 | submit_code(string(body), attendance_code, "https://floridapoly.aplusattendance.com/canvas/student/") | ||
| 28 | |||
| 29 | // fmt.Println(string(body)) | ||
| 30 | } | ||
| 31 | |||
| 32 | func get_aplus(token string, link string, client http.Client) string { | ||
| 33 | resp, _ := client.Get(link) | ||
| 34 | |||
| 35 | body, _ := io.ReadAll(resp.Body) | ||
| 36 | |||
| 37 | var aplus Aplus | ||
| 38 | json.Unmarshal(body, &aplus) | ||
| 39 | |||
| 40 | return aplus.URL | ||
| 41 | } | ||
| 42 | |||
| 43 | func submit_code(cur_body string, attendance_code string, current_url string) { | ||
| 44 | // the links to submit the code for a class is under the dayPanel div | 16 | // the links to submit the code for a class is under the dayPanel div |
| 45 | daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") | 17 | daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") |
| 46 | 18 | ||
| @@ -92,6 +64,33 @@ func submit_code(cur_body string, attendance_code string, current_url string) { | |||
| 92 | } | 64 | } |
| 93 | } | 65 | } |
| 94 | 66 | ||
| 67 | func launch_aplus(course_code int) string { | ||
| 68 | aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s", | ||
| 69 | base_link, course_code, external_tools_code, token) | ||
| 70 | aplus := get_aplus(token, aplus_link, client) | ||
| 71 | |||
| 72 | resp, _ := client.Get(aplus) | ||
| 73 | body, _ := io.ReadAll(resp.Body) | ||
| 74 | |||
| 75 | form_str := get_form_from_request_body(body) | ||
| 76 | form_values := parse_form(form_str) | ||
| 77 | |||
| 78 | resp, _ = client.PostForm(base_aplus_link, form_values) | ||
| 79 | body, _ = io.ReadAll(resp.Body) | ||
| 80 | return string(body) | ||
| 81 | } | ||
| 82 | |||
| 83 | func get_aplus(token string, link string, client http.Client) string { | ||
| 84 | resp, _ := client.Get(link) | ||
| 85 | |||
| 86 | body, _ := io.ReadAll(resp.Body) | ||
| 87 | |||
| 88 | var aplus Aplus | ||
| 89 | json.Unmarshal(body, &aplus) | ||
| 90 | |||
| 91 | return aplus.URL | ||
| 92 | } | ||
| 93 | |||
| 95 | func get_form_from_request_body(req_body []byte) string { | 94 | func get_form_from_request_body(req_body []byte) string { |
| 96 | body_str := string(req_body) | 95 | body_str := string(req_body) |
| 97 | form_start := strings.Index(body_str, "<form") | 96 | form_start := strings.Index(body_str, "<form") |
