Reorganization

This commit is contained in:
Juan Roig 2023-11-14 18:04:29 -05:00
parent 7b613b030d
commit 329f8dfe02
3 changed files with 34 additions and 34 deletions

View File

@ -10,37 +10,9 @@ import (
"strings" "strings"
) )
func launch_aplus(course_code int, attendance_code string) { func submit_code(course_code int, attendance_code string) {
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s", cur_body := launch_aplus(course_code)
base_link, course_code, external_tools_code, token) current_url := fmt.Sprintf("%s/student/", base_aplus_link)
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("https://floridapoly.aplusattendance.com/canvas", form_values)
body, _ = io.ReadAll(resp.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 {
resp, _ := client.Get(link)
body, _ := io.ReadAll(resp.Body)
var aplus Aplus
json.Unmarshal(body, &aplus)
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 // the links to submit the code for a class is under the dayPanel div
daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"")
@ -92,6 +64,33 @@ func submit_code(cur_body string, attendance_code string, current_url string) {
} }
} }
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 { 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")

View File

@ -13,6 +13,7 @@ import (
func initialize() { func initialize() {
base_link = "https://floridapolytechnic.instructure.com/api/v1" base_link = "https://floridapolytechnic.instructure.com/api/v1"
base_aplus_link = "https://floridapoly.aplusattendance.com/canvas"
token = os.Getenv("CANVAS_API_KEY") token = os.Getenv("CANVAS_API_KEY")
external_tools_code = 913 external_tools_code = 913
jar, _ := cookiejar.New(&cookiejar.Options{ jar, _ := cookiejar.New(&cookiejar.Options{

View File

@ -5,6 +5,7 @@ import (
) )
var base_link string var base_link string
var base_aplus_link string
var token string var token string
var external_tools_code int var external_tools_code int
var client http.Client var client http.Client
@ -12,9 +13,8 @@ var client http.Client
func main() { func main() {
initialize() initialize()
// select_course() course_code := 7326
course_code := 7329 submit_code(course_code, "A1B2C")
launch_aplus(course_code, "A1B2C")
// enter_code() // enter_code()
} }