2023-10-27 19:02:38 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-11-20 10:06:35 -05:00
|
|
|
"flag"
|
2023-11-14 22:42:25 -05:00
|
|
|
"fmt"
|
2023-10-27 19:02:38 -04:00
|
|
|
"net/http"
|
2023-11-15 03:58:38 -05:00
|
|
|
"os"
|
2024-01-12 19:15:35 -05:00
|
|
|
"runtime/pprof"
|
2023-10-27 19:02:38 -04:00
|
|
|
)
|
|
|
|
|
2023-11-07 00:21:48 -05:00
|
|
|
var base_link string
|
2023-11-20 10:06:35 -05:00
|
|
|
var base_aplus_link string
|
|
|
|
var external_tools_code int
|
2023-11-07 00:21:48 -05:00
|
|
|
var token string
|
2023-11-13 02:08:03 -05:00
|
|
|
var client http.Client
|
2023-11-21 11:07:28 -05:00
|
|
|
var verbose bool
|
2023-11-07 00:21:48 -05:00
|
|
|
|
2023-11-20 10:06:35 -05:00
|
|
|
func usage() {
|
2023-11-20 15:41:28 -05:00
|
|
|
fmt.Println("Usage: aplus --code attendance_code --course course_code [--list] [--listfav] [--help]")
|
|
|
|
fmt.Println(" -c, --code\tfive character attendance code")
|
|
|
|
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")
|
2023-11-21 11:07:28 -05:00
|
|
|
fmt.Println(" -v, --verbose\tprints with verbose output")
|
2023-11-20 15:41:28 -05:00
|
|
|
fmt.Println(" -h, --help\tdisplays this help message")
|
2024-01-12 19:15:35 -05:00
|
|
|
fmt.Println(" -p, --profile\twrites cpu profile to a file")
|
2023-11-20 10:06:35 -05:00
|
|
|
}
|
|
|
|
|
2023-10-27 19:02:38 -04:00
|
|
|
func main() {
|
2023-11-07 00:21:48 -05:00
|
|
|
initialize()
|
2023-11-04 01:55:30 -04:00
|
|
|
|
2023-11-20 10:06:35 -05:00
|
|
|
var code string
|
|
|
|
var course int
|
|
|
|
var listall bool
|
|
|
|
var listfav bool
|
|
|
|
var help bool
|
2024-01-12 19:15:35 -05:00
|
|
|
var cpuprofile string
|
2023-11-15 03:58:38 -05:00
|
|
|
|
2023-11-20 10:06:35 -05:00
|
|
|
flag.StringVar(&code, "code", "", "5 character attendance code")
|
|
|
|
flag.StringVar(&code, "c", "", "5 character attendance code")
|
|
|
|
flag.IntVar(&course, "course", -1, "canvas course code")
|
|
|
|
flag.IntVar(&course, "C", -1, "canvas course code")
|
|
|
|
flag.BoolVar(&listall, "list", false, "list all canvas courses")
|
|
|
|
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")
|
2023-11-21 11:07:28 -05:00
|
|
|
flag.BoolVar(&verbose, "verbose", false, "verbose output")
|
|
|
|
flag.BoolVar(&verbose, "v", false, "verbose output")
|
2023-11-20 10:06:35 -05:00
|
|
|
flag.BoolVar(&help, "help", false, "view usage message")
|
|
|
|
flag.BoolVar(&help, "h", false, "view usage message")
|
2024-01-12 19:15:35 -05:00
|
|
|
flag.StringVar(&cpuprofile, "p", "", "CPU profiling report location")
|
|
|
|
flag.StringVar(&cpuprofile, "profile", "", "CPU profiling report location")
|
2023-10-30 17:58:38 -04:00
|
|
|
|
2023-11-20 10:06:35 -05:00
|
|
|
flag.Parse()
|
|
|
|
|
2024-01-12 19:15:35 -05:00
|
|
|
if cpuprofile != "" {
|
|
|
|
cpuf, err := os.Create(cpuprofile)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
defer cpuf.Close()
|
|
|
|
|
|
|
|
err = pprof.StartCPUProfile(cpuf)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
defer pprof.StopCPUProfile()
|
|
|
|
}
|
|
|
|
|
2023-11-20 15:41:28 -05:00
|
|
|
if code == "" && course == -1 && !listall && !listfav && !help {
|
2023-11-20 10:06:35 -05:00
|
|
|
usage()
|
|
|
|
os.Exit(1)
|
2023-11-15 03:58:38 -05:00
|
|
|
}
|
2023-11-14 22:42:25 -05:00
|
|
|
|
2023-11-20 15:41:28 -05:00
|
|
|
if listall {
|
2024-01-11 18:36:22 -05:00
|
|
|
_ = list_all_courses(false)
|
2023-11-20 10:06:35 -05:00
|
|
|
os.Exit(0)
|
2023-11-14 22:42:25 -05:00
|
|
|
}
|
|
|
|
|
2023-11-20 15:41:28 -05:00
|
|
|
if listfav {
|
2023-11-14 22:42:25 -05:00
|
|
|
list_favorite_courses()
|
2023-11-20 10:06:35 -05:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2023-11-20 15:41:28 -05:00
|
|
|
if help {
|
2023-11-20 10:06:35 -05:00
|
|
|
usage()
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2023-11-20 15:41:28 -05:00
|
|
|
if len(code) == 5 && course != -1 {
|
2023-11-20 10:06:35 -05:00
|
|
|
fmt.Printf("%d %s\n", course, code)
|
|
|
|
submit_code(course, code)
|
2023-11-20 15:41:28 -05:00
|
|
|
} else if code == "" && course != -1 {
|
|
|
|
fmt.Println("Attendance code not provided")
|
|
|
|
usage()
|
|
|
|
os.Exit(1)
|
|
|
|
} else if len(code) != 5 {
|
|
|
|
fmt.Println("Attendance code must be 5 characters long")
|
2023-11-20 10:06:35 -05:00
|
|
|
usage()
|
|
|
|
os.Exit(1)
|
2024-01-11 18:36:22 -05:00
|
|
|
} else if len(code) == 5 && course == -1 {
|
|
|
|
fmt.Println("Checking which course to send the code to")
|
|
|
|
submit_code_sans_course(code)
|
2023-11-14 22:42:25 -05:00
|
|
|
}
|
2023-11-04 01:55:30 -04:00
|
|
|
}
|