diff options
| -rw-r--r-- | aplus.go | 61 | ||||
| -rw-r--r-- | canvas.go | 1 | ||||
| -rw-r--r-- | main.go | 6 |
3 files changed, 34 insertions, 34 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") |
| @@ -13,6 +13,7 @@ import ( | |||
| 13 | 13 | ||
| 14 | func initialize() { | 14 | func initialize() { |
| 15 | base_link = "https://floridapolytechnic.instructure.com/api/v1" | 15 | base_link = "https://floridapolytechnic.instructure.com/api/v1" |
| 16 | base_aplus_link = "https://floridapoly.aplusattendance.com/canvas" | ||
| 16 | token = os.Getenv("CANVAS_API_KEY") | 17 | token = os.Getenv("CANVAS_API_KEY") |
| 17 | external_tools_code = 913 | 18 | external_tools_code = 913 |
| 18 | jar, _ := cookiejar.New(&cookiejar.Options{ | 19 | jar, _ := cookiejar.New(&cookiejar.Options{ |
| @@ -5,6 +5,7 @@ import ( | |||
| 5 | ) | 5 | ) |
| 6 | 6 | ||
| 7 | var base_link string | 7 | var base_link string |
| 8 | var base_aplus_link string | ||
| 8 | var token string | 9 | var token string |
| 9 | var external_tools_code int | 10 | var external_tools_code int |
| 10 | var client http.Client | 11 | var client http.Client |
| @@ -12,9 +13,8 @@ var client http.Client | |||
| 12 | func main() { | 13 | func main() { |
| 13 | initialize() | 14 | initialize() |
| 14 | 15 | ||
| 15 | // select_course() | 16 | course_code := 7326 |
| 16 | course_code := 7329 | 17 | submit_code(course_code, "A1B2C") |
| 17 | launch_aplus(course_code, "A1B2C") | ||
| 18 | 18 | ||
| 19 | // enter_code() | 19 | // enter_code() |
| 20 | } | 20 | } |
