commit 329f8dfe029025d591cf3e111dc842a7f4c2a43f
parent 7b613b030da2432830a9f00bfc6aeb9e59bcd728
Author: Juan Roig <jaroig@outlook.com>
Date: Tue, 14 Nov 2023 18:04:29 -0500
Reorganization
Diffstat:
3 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/aplus.go b/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")
diff --git a/canvas.go b/canvas.go
@@ -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{
diff --git a/main.go b/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()
}