commit e28dc923074ff7445d23cb97a04233f6192a69be
parent 329f8dfe029025d591cf3e111dc842a7f4c2a43f
Author: Juan Roig <jaroig@outlook.com>
Date: Tue, 14 Nov 2023 22:42:25 -0500
Add flags, update README
Diffstat:
4 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/README.md b/README.md
@@ -1,23 +1,16 @@
-# aplus
+# aplus command line utility
-This is an aplus cli utility created for students at Florida Polytechnic University to submit their aplus codes through the CLI.
+This is an cli utility initially created for students at Florida Polytechnic University to submit their aplus codes.
In time, we intend to generalize this utility to all universities.
In 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.
## Usage
### List all courses and canvas course codes
-aplus
-aplus --list-courses
-aplus -l
+aplus --list-all
### List favorite courses and canvas course codes
aplus --list-favorites
-### Enter code immediately for an active code
-aplus -c <code>
-aplus --code <code>
-
### Enter code for a specified course
-aplus -c <code> --course <course_code>
-aplus --code <code> --course <course_code>
-\ No newline at end of file
+aplus --code <code> --course <canvas_course_number>
+\ No newline at end of file
diff --git a/aplus.go b/aplus.go
@@ -12,6 +12,9 @@ import (
func submit_code(course_code int, attendance_code string) {
cur_body := launch_aplus(course_code)
+
+ fmt.Printf("%s", cur_body)
+
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\"")
@@ -37,21 +40,13 @@ func submit_code(course_code int, attendance_code string) {
resp, _ := client.Get(link_url)
body, _ := io.ReadAll(resp.Body)
- fmt.Println(string(body))
-
form_str := get_form_from_request_body(body)
form_values := parse_form(form_str)
form_values["ctl01$sessionCode"][0] = attendance_code
- //fmt.Println(form_str)
- //fmt.Println(form_values)
-
resp, _ = client.PostForm(link_url, form_values)
body, _ = io.ReadAll(resp.Body)
- fmt.Println(string(body))
- fmt.Println(resp)
-
if strings.Index(string(body), "ctl01_errorMessage") != -1 {
errormsg_start := strings.Index(string(body), "ctl01_errorMessage")
errormsg_start += strings.Index(string(body)[errormsg_start:], "Text\">")
diff --git a/go.mod b/go.mod
@@ -2,4 +2,4 @@ module codeberg.org/flpolyaplus/aplus
go 1.21.3
-require golang.org/x/net v0.18.0 // indirect
+require golang.org/x/net v0.18.0
diff --git a/main.go b/main.go
@@ -1,6 +1,8 @@
package main
import (
+ "flag"
+ "fmt"
"net/http"
)
@@ -13,8 +15,25 @@ var client http.Client
func main() {
initialize()
- course_code := 7326
- submit_code(course_code, "A1B2C")
+ code := flag.String("code", "", "Code to enter")
+ course := flag.Int("course", -1, "Canvas course number")
+ list_all := flag.Bool("list-all", false, "List all courses")
+ list_favorites := flag.Bool("list-favorites", false, "List favorite courses")
- // enter_code()
+ flag.Parse()
+
+ if *list_all {
+ list_all_courses()
+ }
+
+ if *list_favorites {
+ list_favorite_courses()
+ }
+
+ if *code != "" && *course != -1 {
+ fmt.Printf("%d %s", *course, *code)
+ submit_code(*course, *code)
+ }
+
+ submit_code(7329, "asdkl")
}