add verbose flag

This commit is contained in:
Vineet K 2023-11-21 11:07:28 -05:00
parent 3065b05ed4
commit 6b0ed0f177
3 changed files with 17 additions and 7 deletions

View File

@ -14,7 +14,9 @@ import (
func submit_code(course_code int, attendance_code string) {
cur_body := launch_aplus(course_code)
fmt.Printf("%s", cur_body)
if verbose {
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
@ -33,10 +35,12 @@ func submit_code(course_code int, attendance_code string) {
link_url := current_url + cur_body[link_start:link_end]
link_url = html.UnescapeString(link_url)
fmt.Println("!!!")
fmt.Printf("%i %i %i\n", daypanel_start, link_start, link_end)
fmt.Println(link_url)
fmt.Println("!!!")
if verbose {
fmt.Println("!!!")
fmt.Printf("%i %i %i\n", daypanel_start, link_start, link_end)
fmt.Println(link_url)
fmt.Println("!!!")
}
resp, _ := client.Get(link_url)
body, _ := io.ReadAll(resp.Body)

View File

@ -23,8 +23,10 @@ func initialize() {
client = http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
fmt.Println("Redirected to:", req.URL)
fmt.Println(req.Cookies())
if verbose {
fmt.Println("Redirected to:", req.URL)
fmt.Println(req.Cookies())
}
return nil
},
Jar: jar,

View File

@ -12,6 +12,7 @@ var base_aplus_link string
var external_tools_code int
var token string
var client http.Client
var verbose bool
func usage() {
fmt.Println("Usage: aplus --code attendance_code --course course_code [--list] [--listfav] [--help]")
@ -19,6 +20,7 @@ func usage() {
fmt.Println(" -C, --course\tcanvas course ID")
fmt.Println(" -L, --list\tlists canvas courses with name and ID")
fmt.Println(" -F, --listfav\tlists favourited canvas courses with name and ID")
fmt.Println(" -v, --verbose\tprints with verbose output")
fmt.Println(" -h, --help\tdisplays this help message")
}
@ -39,6 +41,8 @@ func main() {
flag.BoolVar(&listall, "L", false, "list all canvas courses")
flag.BoolVar(&listfav, "listfav", false, "list favorited canvas courses")
flag.BoolVar(&listfav, "F", false, "list favorited canvas courses")
flag.BoolVar(&verbose, "verbose", false, "verbose output")
flag.BoolVar(&verbose, "v", false, "verbose output")
flag.BoolVar(&help, "help", false, "view usage message")
flag.BoolVar(&help, "h", false, "view usage message")