mirror of
https://codeberg.org/flpolyaplus/aplus.git
synced 2024-11-24 10:20:30 -05:00
add rudimentary messy function for submitting aplus code
It is very messy, but later using golang's HTML parser should help make it more readable.
This commit is contained in:
parent
aa16b741d5
commit
7b613b030d
58
aplus.go
58
aplus.go
@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func launch_aplus(course_code int) {
|
func launch_aplus(course_code int, attendance_code string) {
|
||||||
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s",
|
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s",
|
||||||
base_link, course_code, external_tools_code, token)
|
base_link, course_code, external_tools_code, token)
|
||||||
aplus := get_aplus(token, aplus_link, client)
|
aplus := get_aplus(token, aplus_link, client)
|
||||||
@ -24,7 +24,9 @@ func launch_aplus(course_code int) {
|
|||||||
resp, _ = client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
|
resp, _ = client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
|
||||||
body, _ = io.ReadAll(resp.Body)
|
body, _ = io.ReadAll(resp.Body)
|
||||||
|
|
||||||
fmt.Println(string(body))
|
submit_code(string(body), attendance_code, "https://floridapoly.aplusattendance.com/canvas/student/")
|
||||||
|
|
||||||
|
// fmt.Println(string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
func get_aplus(token string, link string, client http.Client) string {
|
func get_aplus(token string, link string, client http.Client) string {
|
||||||
@ -38,6 +40,58 @@ func get_aplus(token string, link string, client http.Client) string {
|
|||||||
return aplus.URL
|
return aplus.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func submit_code(cur_body string, attendance_code string, current_url string) {
|
||||||
|
// the links to submit the code for a class is under the dayPanel div
|
||||||
|
daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"")
|
||||||
|
|
||||||
|
// link_start - link_end is to extract the URL
|
||||||
|
// TODO: make this more elegant to allow multiple of these links
|
||||||
|
// (maybe use an html parser)
|
||||||
|
// or at least use extract_attribute()
|
||||||
|
link_start := daypanel_start
|
||||||
|
link_start += strings.Index(cur_body[link_start:], "<a href=\"./?module")
|
||||||
|
link_start += len("<a href=\"")
|
||||||
|
link_end := link_start
|
||||||
|
link_end += strings.Index(cur_body[link_end:], "\"")
|
||||||
|
|
||||||
|
link_url := current_url + cur_body[link_start:link_end]
|
||||||
|
link_url = html.UnescapeString(link_url)
|
||||||
|
|
||||||
|
fmt.Println("!!!")
|
||||||
|
fmt.Printf("%i %i %i\n", daypanel_start, link_start, link_end)
|
||||||
|
fmt.Println(link_url)
|
||||||
|
fmt.Println("!!!")
|
||||||
|
|
||||||
|
resp, _ := client.Get(link_url)
|
||||||
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
|
||||||
|
fmt.Println(string(body))
|
||||||
|
|
||||||
|
form_str := get_form_from_request_body(body)
|
||||||
|
form_values := parse_form(form_str)
|
||||||
|
form_values["ctl01$sessionCode"][0] = attendance_code
|
||||||
|
|
||||||
|
//fmt.Println(form_str)
|
||||||
|
//fmt.Println(form_values)
|
||||||
|
|
||||||
|
resp, _ = client.PostForm(link_url, form_values)
|
||||||
|
body, _ = io.ReadAll(resp.Body)
|
||||||
|
|
||||||
|
fmt.Println(string(body))
|
||||||
|
fmt.Println(resp)
|
||||||
|
|
||||||
|
if strings.Index(string(body), "ctl01_errorMessage") != -1 {
|
||||||
|
errormsg_start := strings.Index(string(body), "ctl01_errorMessage")
|
||||||
|
errormsg_start += strings.Index(string(body)[errormsg_start:], "Text\">")
|
||||||
|
errormsg_start += len("Text\">")
|
||||||
|
errormsg_end := errormsg_start
|
||||||
|
errormsg_end += strings.Index(string(body)[errormsg_start:], "<")
|
||||||
|
fmt.Println(string(body)[errormsg_start:errormsg_end])
|
||||||
|
} else if strings.Index(string(body), "ctl02_codeSuccessMessage") != -1 {
|
||||||
|
fmt.Println("Code successfully recorded")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func get_form_from_request_body(req_body []byte) string {
|
func get_form_from_request_body(req_body []byte) string {
|
||||||
body_str := string(req_body)
|
body_str := string(req_body)
|
||||||
form_start := strings.Index(body_str, "<form")
|
form_start := strings.Index(body_str, "<form")
|
||||||
|
Loading…
Reference in New Issue
Block a user