package main
import (
"encoding/json"
"fmt"
"html"
"io"
"net/http"
"net/url"
"strings"
)
func submit_code(course_code int, attendance_code string) {
cur_body := launch_aplus(course_code)
fmt.Printf("%s", cur_body)
current_url := fmt.Sprintf("%s/student/", base_aplus_link)
// the links to submit the code for a class is under the dayPanel div
daypanel_start := strings.Index(cur_body, "
")
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 launch_aplus(course_code int) string {
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s",
base_link, course_code, external_tools_code, token)
aplus := get_aplus(token, aplus_link, client)
resp, _ := client.Get(aplus)
body, _ := io.ReadAll(resp.Body)
form_str := get_form_from_request_body(body)
form_values := parse_form(form_str)
resp, _ = client.PostForm(base_aplus_link, form_values)
body, _ = io.ReadAll(resp.Body)
return string(body)
}
func get_aplus(token string, link string, client http.Client) string {
resp, _ := client.Get(link)
body, _ := io.ReadAll(resp.Body)
var aplus Aplus
json.Unmarshal(body, &aplus)
return aplus.URL
}
func get_form_from_request_body(req_body []byte) string {
body_str := string(req_body)
form_start := strings.Index(body_str, "