mirror of
https://codeberg.org/flpolyaplus/aplus.git
synced 2024-11-21 17:00:30 -05:00
Reorganization
This commit is contained in:
parent
7b613b030d
commit
329f8dfe02
61
aplus.go
61
aplus.go
@ -10,37 +10,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
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",
|
||||
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("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) {
|
||||
func submit_code(course_code int, attendance_code string) {
|
||||
cur_body := launch_aplus(course_code)
|
||||
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, "<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 {
|
||||
body_str := string(req_body)
|
||||
form_start := strings.Index(body_str, "<form")
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
|
||||
func initialize() {
|
||||
base_link = "https://floridapolytechnic.instructure.com/api/v1"
|
||||
base_aplus_link = "https://floridapoly.aplusattendance.com/canvas"
|
||||
token = os.Getenv("CANVAS_API_KEY")
|
||||
external_tools_code = 913
|
||||
jar, _ := cookiejar.New(&cookiejar.Options{
|
||||
|
6
main.go
6
main.go
@ -5,6 +5,7 @@ import (
|
||||
)
|
||||
|
||||
var base_link string
|
||||
var base_aplus_link string
|
||||
var token string
|
||||
var external_tools_code int
|
||||
var client http.Client
|
||||
@ -12,9 +13,8 @@ var client http.Client
|
||||
func main() {
|
||||
initialize()
|
||||
|
||||
// select_course()
|
||||
course_code := 7329
|
||||
launch_aplus(course_code, "A1B2C")
|
||||
course_code := 7326
|
||||
submit_code(course_code, "A1B2C")
|
||||
|
||||
// enter_code()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user