summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Roig <jaroig@outlook.com>2023-11-14 18:04:29 -0500
committerJuan Roig <jaroig@outlook.com>2023-11-14 18:04:29 -0500
commit329f8dfe029025d591cf3e111dc842a7f4c2a43f (patch)
treed4beebd24a00ed8503916c5b0f68840191d177fc
parent7b613b030da2432830a9f00bfc6aeb9e59bcd728 (diff)
Reorganization
-rw-r--r--aplus.go61
-rw-r--r--canvas.go1
-rw-r--r--main.go6
3 files changed, 34 insertions, 34 deletions
diff --git a/aplus.go b/aplus.go
index ec17ac2..b9e6a13 100644
--- a/aplus.go
+++ b/aplus.go
@@ -10,37 +10,9 @@ import (
10 "strings" 10 "strings"
11) 11)
12 12
13func launch_aplus(course_code int, attendance_code string) { 13func submit_code(course_code int, attendance_code string) {
14 aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s", 14 cur_body := launch_aplus(course_code)
15 base_link, course_code, external_tools_code, token) 15 current_url := fmt.Sprintf("%s/student/", base_aplus_link)
16 aplus := get_aplus(token, aplus_link, client)
17
18 resp, _ := client.Get(aplus)
19 body, _ := io.ReadAll(resp.Body)
20
21 form_str := get_form_from_request_body(body)
22 form_values := parse_form(form_str)
23
24 resp, _ = client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
25 body, _ = io.ReadAll(resp.Body)
26
27 submit_code(string(body), attendance_code, "https://floridapoly.aplusattendance.com/canvas/student/")
28
29 // fmt.Println(string(body))
30}
31
32func get_aplus(token string, link string, client http.Client) string {
33 resp, _ := client.Get(link)
34
35 body, _ := io.ReadAll(resp.Body)
36
37 var aplus Aplus
38 json.Unmarshal(body, &aplus)
39
40 return aplus.URL
41}
42
43func submit_code(cur_body string, attendance_code string, current_url string) {
44 // the links to submit the code for a class is under the dayPanel div 16 // the links to submit the code for a class is under the dayPanel div
45 daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") 17 daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"")
46 18
@@ -92,6 +64,33 @@ func submit_code(cur_body string, attendance_code string, current_url string) {
92 } 64 }
93} 65}
94 66
67func launch_aplus(course_code int) string {
68 aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s",
69 base_link, course_code, external_tools_code, token)
70 aplus := get_aplus(token, aplus_link, client)
71
72 resp, _ := client.Get(aplus)
73 body, _ := io.ReadAll(resp.Body)
74
75 form_str := get_form_from_request_body(body)
76 form_values := parse_form(form_str)
77
78 resp, _ = client.PostForm(base_aplus_link, form_values)
79 body, _ = io.ReadAll(resp.Body)
80 return string(body)
81}
82
83func get_aplus(token string, link string, client http.Client) string {
84 resp, _ := client.Get(link)
85
86 body, _ := io.ReadAll(resp.Body)
87
88 var aplus Aplus
89 json.Unmarshal(body, &aplus)
90
91 return aplus.URL
92}
93
95func get_form_from_request_body(req_body []byte) string { 94func get_form_from_request_body(req_body []byte) string {
96 body_str := string(req_body) 95 body_str := string(req_body)
97 form_start := strings.Index(body_str, "<form") 96 form_start := strings.Index(body_str, "<form")
diff --git a/canvas.go b/canvas.go
index c31265a..2052373 100644
--- a/canvas.go
+++ b/canvas.go
@@ -13,6 +13,7 @@ import (
13 13
14func initialize() { 14func initialize() {
15 base_link = "https://floridapolytechnic.instructure.com/api/v1" 15 base_link = "https://floridapolytechnic.instructure.com/api/v1"
16 base_aplus_link = "https://floridapoly.aplusattendance.com/canvas"
16 token = os.Getenv("CANVAS_API_KEY") 17 token = os.Getenv("CANVAS_API_KEY")
17 external_tools_code = 913 18 external_tools_code = 913
18 jar, _ := cookiejar.New(&cookiejar.Options{ 19 jar, _ := cookiejar.New(&cookiejar.Options{
diff --git a/main.go b/main.go
index 71db90b..6e4205e 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ import (
5) 5)
6 6
7var base_link string 7var base_link string
8var base_aplus_link string
8var token string 9var token string
9var external_tools_code int 10var external_tools_code int
10var client http.Client 11var client http.Client
@@ -12,9 +13,8 @@ var client http.Client
12func main() { 13func main() {
13 initialize() 14 initialize()
14 15
15 // select_course() 16 course_code := 7326
16 course_code := 7329 17 submit_code(course_code, "A1B2C")
17 launch_aplus(course_code, "A1B2C")
18 18
19 // enter_code() 19 // enter_code()
20} 20}