diff --git a/aplus.go b/aplus.go
index 2e2ab0a..e546b6c 100644
--- a/aplus.go
+++ b/aplus.go
@@ -7,7 +7,10 @@ import (
"io"
"net/http"
"net/url"
+ "regexp"
"strings"
+ "strconv"
+ "time"
)
func submit_code(course_code int, attendance_code string) bool {
@@ -176,3 +179,54 @@ func submit_code_sans_course(attendance_code string) {
fmt.Println("Could not submit code", attendance_code, "to any course")
}
+
+func timetable(course_code int) {
+ cur_body := launch_aplus(course_code)
+ if cur_body == "" {
+ return
+ }
+
+ if verbose {
+ fmt.Printf("%s", cur_body)
+ }
+
+ if strings.Contains(cur_body, "Student not known") {
+ fmt.Println("Student not known. This course must first be visited by an instructor for students to have access.")
+ return
+ }
+
+ current_url := fmt.Sprintf("%s/student/", base_aplus_link)
+ tt_start := strings.Index(cur_body, "
[^<]*")
+
+ dates, statuses := re_date.FindAllString(tt_full, -1), re_status.FindAllString(tt_full, -1)
+ for i := range dates {
+ jsdate := strings.Split(dates[i][9:], ",")
+ year, _ := strconv.Atoi(jsdate[0])
+ month, _ := strconv.Atoi(jsdate[1])
+ day, _ := strconv.Atoi(jsdate[2])
+ hour, _ := strconv.Atoi(jsdate[3])
+ min, _ := strconv.Atoi(jsdate[4])
+ sec, _ := strconv.Atoi(jsdate[5])
+ date := time.Date(year, time.Month(month + 1), day, hour, min, sec, 0, time.UTC).Local()
+
+ fmt.Println(date.Format("Mon Jan 02 15:04:05 MST 2006") + ": " + strings.Replace(statuses[i], "title=\"\">", "", 1))
+ }
+}
diff --git a/main.go b/main.go
index fa99806..cd110ad 100644
--- a/main.go
+++ b/main.go
@@ -16,11 +16,12 @@ var client http.Client
var verbose bool
func usage() {
- fmt.Println("Usage: aplus --code attendance_code --course course_code [--list] [--listfav] [--help]")
+ fmt.Println("Usage: aplus --code attendance_code --course course_code [--list] [--listfav] [--timetable] [--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")
+ fmt.Println(" -t, --timetable\tlists the class sessions in a course")
fmt.Println(" -v, --verbose\tprints with verbose output")
fmt.Println(" -h, --help\tdisplays this help message")
fmt.Println(" -p, --profile\twrites cpu profile to a file")
@@ -33,6 +34,7 @@ func main() {
var course int
var listall bool
var listfav bool
+ var timetable_ bool
var help bool
var cpuprofile string
@@ -44,6 +46,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(&timetable_, "t", false, "lists the class sessions in a course")
+ flag.BoolVar(&timetable_, "timetable", false, "lists the class sessions in a course")
flag.BoolVar(&verbose, "verbose", false, "verbose output")
flag.BoolVar(&verbose, "v", false, "verbose output")
flag.BoolVar(&help, "help", false, "view usage message")
@@ -84,6 +88,15 @@ func main() {
os.Exit(0)
}
+ if course != -1 && timetable_ {
+ timetable(course)
+ os.Exit(0)
+ } else if course == -1 && timetable_ {
+ fmt.Println("Course code required for timetable")
+ usage()
+ os.Exit(1)
+ }
+
if help {
usage()
os.Exit(0)