summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2023-11-21 11:07:28 -0500
committervin <git@vineetk.net>2023-11-21 11:07:28 -0500
commit6b0ed0f177f051961d45f7b6eaf120911c651331 (patch)
tree95a472147f5631aeca5f998ab3608c1735f6aa54
parent3065b05ed45a04f401e8aec7d770b9e7a22c8ec4 (diff)
add verbose flag
-rw-r--r--aplus.go14
-rw-r--r--canvas.go6
-rw-r--r--main.go4
3 files changed, 17 insertions, 7 deletions
diff --git a/aplus.go b/aplus.go
index 96fbd92..dfc73e1 100644
--- a/aplus.go
+++ b/aplus.go
@@ -14,7 +14,9 @@ import (
14func submit_code(course_code int, attendance_code string) { 14func submit_code(course_code int, attendance_code string) {
15 cur_body := launch_aplus(course_code) 15 cur_body := launch_aplus(course_code)
16 16
17 fmt.Printf("%s", cur_body) 17 if verbose {
18 fmt.Printf("%s", cur_body)
19 }
18 20
19 current_url := fmt.Sprintf("%s/student/", base_aplus_link) 21 current_url := fmt.Sprintf("%s/student/", base_aplus_link)
20 // the links to submit the code for a class is under the dayPanel div 22 // the links to submit the code for a class is under the dayPanel div
@@ -33,10 +35,12 @@ func submit_code(course_code int, attendance_code string) {
33 link_url := current_url + cur_body[link_start:link_end] 35 link_url := current_url + cur_body[link_start:link_end]
34 link_url = html.UnescapeString(link_url) 36 link_url = html.UnescapeString(link_url)
35 37
36 fmt.Println("!!!") 38 if verbose {
37 fmt.Printf("%i %i %i\n", daypanel_start, link_start, link_end) 39 fmt.Println("!!!")
38 fmt.Println(link_url) 40 fmt.Printf("%i %i %i\n", daypanel_start, link_start, link_end)
39 fmt.Println("!!!") 41 fmt.Println(link_url)
42 fmt.Println("!!!")
43 }
40 44
41 resp, _ := client.Get(link_url) 45 resp, _ := client.Get(link_url)
42 body, _ := io.ReadAll(resp.Body) 46 body, _ := io.ReadAll(resp.Body)
diff --git a/canvas.go b/canvas.go
index d781717..2991ebd 100644
--- a/canvas.go
+++ b/canvas.go
@@ -23,8 +23,10 @@ func initialize() {
23 23
24 client = http.Client{ 24 client = http.Client{
25 CheckRedirect: func(req *http.Request, via []*http.Request) error { 25 CheckRedirect: func(req *http.Request, via []*http.Request) error {
26 fmt.Println("Redirected to:", req.URL) 26 if verbose {
27 fmt.Println(req.Cookies()) 27 fmt.Println("Redirected to:", req.URL)
28 fmt.Println(req.Cookies())
29 }
28 return nil 30 return nil
29 }, 31 },
30 Jar: jar, 32 Jar: jar,
diff --git a/main.go b/main.go
index 0ebd8f7..3390dbd 100644
--- a/main.go
+++ b/main.go
@@ -12,6 +12,7 @@ var base_aplus_link string
12var external_tools_code int 12var external_tools_code int
13var token string 13var token string
14var client http.Client 14var client http.Client
15var verbose bool
15 16
16func usage() { 17func usage() {
17 fmt.Println("Usage: aplus --code attendance_code --course course_code [--list] [--listfav] [--help]") 18 fmt.Println("Usage: aplus --code attendance_code --course course_code [--list] [--listfav] [--help]")
@@ -19,6 +20,7 @@ func usage() {
19 fmt.Println(" -C, --course\tcanvas course ID") 20 fmt.Println(" -C, --course\tcanvas course ID")
20 fmt.Println(" -L, --list\tlists canvas courses with name and ID") 21 fmt.Println(" -L, --list\tlists canvas courses with name and ID")
21 fmt.Println(" -F, --listfav\tlists favourited canvas courses with name and ID") 22 fmt.Println(" -F, --listfav\tlists favourited canvas courses with name and ID")
23 fmt.Println(" -v, --verbose\tprints with verbose output")
22 fmt.Println(" -h, --help\tdisplays this help message") 24 fmt.Println(" -h, --help\tdisplays this help message")
23} 25}
24 26
@@ -39,6 +41,8 @@ func main() {
39 flag.BoolVar(&listall, "L", false, "list all canvas courses") 41 flag.BoolVar(&listall, "L", false, "list all canvas courses")
40 flag.BoolVar(&listfav, "listfav", false, "list favorited canvas courses") 42 flag.BoolVar(&listfav, "listfav", false, "list favorited canvas courses")
41 flag.BoolVar(&listfav, "F", false, "list favorited canvas courses") 43 flag.BoolVar(&listfav, "F", false, "list favorited canvas courses")
44 flag.BoolVar(&verbose, "verbose", false, "verbose output")
45 flag.BoolVar(&verbose, "v", false, "verbose output")
42 flag.BoolVar(&help, "help", false, "view usage message") 46 flag.BoolVar(&help, "help", false, "view usage message")
43 flag.BoolVar(&help, "h", false, "view usage message") 47 flag.BoolVar(&help, "h", false, "view usage message")
44 48