aplus/main.go

75 lines
1.5 KiB
Go
Raw Normal View History

2023-10-27 19:02:38 -04:00
package main
import (
"flag"
2023-11-14 22:42:25 -05:00
"fmt"
2023-10-27 19:02:38 -04:00
"net/http"
"os"
2023-10-27 19:02:38 -04:00
)
var base_link string
var base_aplus_link string
var external_tools_code int
var token string
var client http.Client
func usage() {
fmt.Println("Usage: aplus [--code attendance_code --course course_code] [--list] [--listfav] [--help]")
}
2023-10-27 19:02:38 -04:00
func main() {
initialize()
2023-11-04 01:55:30 -04:00
var code string
var course int
var listall bool
var listfav bool
var help bool
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")
flag.BoolVar(&help, "help", false, "view usage message")
flag.BoolVar(&help, "h", false, "view usage message")
2023-10-30 17:58:38 -04:00
flag.Parse()
if (code == "" && course == -1 && !listall && !listfav) {
usage()
os.Exit(1)
}
2023-11-14 22:42:25 -05:00
if (listall) {
2023-11-14 22:42:25 -05:00
list_all_courses()
os.Exit(0)
2023-11-14 22:42:25 -05:00
}
if (listfav) {
2023-11-14 22:42:25 -05:00
list_favorite_courses()
os.Exit(0)
}
if (help) {
usage()
os.Exit(0)
}
if (len(code) != 5) {
fmt.Println("Attendance code must be 5 characters long")
os.Exit(1)
2023-11-14 22:42:25 -05:00
}
if code != "" && course != -1 {
fmt.Printf("%d %s\n", course, code)
submit_code(course, code)
} else {
usage()
os.Exit(1)
2023-11-14 22:42:25 -05:00
}
2023-11-04 01:55:30 -04:00
}