summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md15
-rw-r--r--aplus.go11
-rw-r--r--go.mod2
-rw-r--r--main.go25
4 files changed, 30 insertions, 23 deletions
diff --git a/README.md b/README.md
index db117a3..99780c3 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,16 @@
1# aplus 1# aplus command line utility
2 2
3This is an aplus cli utility created for students at Florida Polytechnic University to submit their aplus codes through the CLI. 3This is an cli utility initially created for students at Florida Polytechnic University to submit their aplus codes.
4In time, we intend to generalize this utility to all universities. 4In time, we intend to generalize this utility to all universities.
5In the meantime however, any students from other universities wishing to use the utility may change the base_link and external_tools_code (you see this in the URL when you navigate to Aplus attendance within your course) variables. 5In the meantime however, any students from other universities wishing to use the utility may change the base_link and external_tools_code (you see this in the URL when you navigate to Aplus attendance within your course) variables.
6 6
7## Usage 7## Usage
8 8
9### List all courses and canvas course codes 9### List all courses and canvas course codes
10aplus 10aplus --list-all
11aplus --list-courses
12aplus -l
13 11
14### List favorite courses and canvas course codes 12### List favorite courses and canvas course codes
15aplus --list-favorites 13aplus --list-favorites
16 14
17### Enter code immediately for an active code
18aplus -c <code>
19aplus --code <code>
20
21### Enter code for a specified course 15### Enter code for a specified course
22aplus -c <code> --course <course_code> 16aplus --code <code> --course <canvas_course_number> \ No newline at end of file
23aplus --code <code> --course <course_code> \ No newline at end of file
diff --git a/aplus.go b/aplus.go
index b9e6a13..a8d4daf 100644
--- a/aplus.go
+++ b/aplus.go
@@ -12,6 +12,9 @@ import (
12 12
13func submit_code(course_code int, attendance_code string) { 13func submit_code(course_code int, attendance_code string) {
14 cur_body := launch_aplus(course_code) 14 cur_body := launch_aplus(course_code)
15
16 fmt.Printf("%s", cur_body)
17
15 current_url := fmt.Sprintf("%s/student/", base_aplus_link) 18 current_url := fmt.Sprintf("%s/student/", base_aplus_link)
16 // the links to submit the code for a class is under the dayPanel div 19 // the links to submit the code for a class is under the dayPanel div
17 daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"") 20 daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"")
@@ -37,21 +40,13 @@ func submit_code(course_code int, attendance_code string) {
37 resp, _ := client.Get(link_url) 40 resp, _ := client.Get(link_url)
38 body, _ := io.ReadAll(resp.Body) 41 body, _ := io.ReadAll(resp.Body)
39 42
40 fmt.Println(string(body))
41
42 form_str := get_form_from_request_body(body) 43 form_str := get_form_from_request_body(body)
43 form_values := parse_form(form_str) 44 form_values := parse_form(form_str)
44 form_values["ctl01$sessionCode"][0] = attendance_code 45 form_values["ctl01$sessionCode"][0] = attendance_code
45 46
46 //fmt.Println(form_str)
47 //fmt.Println(form_values)
48
49 resp, _ = client.PostForm(link_url, form_values) 47 resp, _ = client.PostForm(link_url, form_values)
50 body, _ = io.ReadAll(resp.Body) 48 body, _ = io.ReadAll(resp.Body)
51 49
52 fmt.Println(string(body))
53 fmt.Println(resp)
54
55 if strings.Index(string(body), "ctl01_errorMessage") != -1 { 50 if strings.Index(string(body), "ctl01_errorMessage") != -1 {
56 errormsg_start := strings.Index(string(body), "ctl01_errorMessage") 51 errormsg_start := strings.Index(string(body), "ctl01_errorMessage")
57 errormsg_start += strings.Index(string(body)[errormsg_start:], "Text\">") 52 errormsg_start += strings.Index(string(body)[errormsg_start:], "Text\">")
diff --git a/go.mod b/go.mod
index 10fe00c..732a265 100644
--- a/go.mod
+++ b/go.mod
@@ -2,4 +2,4 @@ module codeberg.org/flpolyaplus/aplus
2 2
3go 1.21.3 3go 1.21.3
4 4
5require golang.org/x/net v0.18.0 // indirect 5require golang.org/x/net v0.18.0
diff --git a/main.go b/main.go
index 6e4205e..61bf20f 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,8 @@
1package main 1package main
2 2
3import ( 3import (
4 "flag"
5 "fmt"
4 "net/http" 6 "net/http"
5) 7)
6 8
@@ -13,8 +15,25 @@ var client http.Client
13func main() { 15func main() {
14 initialize() 16 initialize()
15 17
16 course_code := 7326 18 code := flag.String("code", "", "Code to enter")
17 submit_code(course_code, "A1B2C") 19 course := flag.Int("course", -1, "Canvas course number")
20 list_all := flag.Bool("list-all", false, "List all courses")
21 list_favorites := flag.Bool("list-favorites", false, "List favorite courses")
18 22
19 // enter_code() 23 flag.Parse()
24
25 if *list_all {
26 list_all_courses()
27 }
28
29 if *list_favorites {
30 list_favorite_courses()
31 }
32
33 if *code != "" && *course != -1 {
34 fmt.Printf("%d %s", *course, *code)
35 submit_code(*course, *code)
36 }
37
38 submit_code(7329, "asdkl")
20} 39}