mirror of
https://codeberg.org/flpolyaplus/aplus.git
synced 2024-11-24 10:20:30 -05:00
start working on submitting course without user-provided course code
This commit is contained in:
parent
e9c76998dc
commit
de8ed98b4c
28
aplus.go
28
aplus.go
@ -11,17 +11,27 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func submit_code(course_code int, attendance_code string) {
|
||||
func submit_code(course_code int, attendance_code string) bool {
|
||||
cur_body := launch_aplus(course_code)
|
||||
|
||||
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 false
|
||||
}
|
||||
|
||||
current_url := fmt.Sprintf("%s/student/", base_aplus_link)
|
||||
// the links to submit the code for a class is under the dayPanel div
|
||||
daypanel_start := strings.Index(cur_body, "<div class=\"dayPanel\"")
|
||||
|
||||
if !strings.Contains(cur_body[daypanel_start:], "<a href=\"./?module") {
|
||||
fmt.Println("No code submitted. Did the professor generate the code or is the class in session?")
|
||||
return false
|
||||
}
|
||||
|
||||
// link_start - link_end is to extract the URL
|
||||
// TODO: make this more elegant to allow multiple of these links
|
||||
// (maybe use an html parser)
|
||||
@ -62,6 +72,8 @@ func submit_code(course_code int, attendance_code string) {
|
||||
} else if strings.Index(string(body), "ctl02_codeSuccessMessage") != -1 {
|
||||
fmt.Println("Code successfully recorded")
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func launch_aplus(course_code int) string {
|
||||
@ -148,3 +160,17 @@ func extract_attribute(input string, attribute string) string {
|
||||
|
||||
return input[start : start+end]
|
||||
}
|
||||
|
||||
func submit_code_sans_course(attendance_code string) {
|
||||
courses := list_all_courses(true)
|
||||
|
||||
for _, course := range courses {
|
||||
fmt.Println("Checking with course", course.ID%10000)
|
||||
if submit_code(int(course.ID%10000), attendance_code) == true {
|
||||
fmt.Println("Submitted code to course", course.ID%10000)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Could not submit code %s to any course\n", attendance_code)
|
||||
}
|
||||
|
@ -83,9 +83,15 @@ func list_all_courses() {
|
||||
|
||||
canvas_courses := get_courses(token, all_courses, client)
|
||||
|
||||
if !onlyreturn {
|
||||
|
||||
for _, course := range canvas_courses {
|
||||
fmt.Printf("%d, %s\n", course.ID%10000, course.Name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return canvas_courses
|
||||
}
|
||||
|
||||
func list_favorite_courses() {
|
||||
|
9
main.go
9
main.go
@ -54,7 +54,7 @@ func main() {
|
||||
}
|
||||
|
||||
if listall {
|
||||
list_all_courses()
|
||||
_ = list_all_courses(false)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
@ -71,10 +71,6 @@ func main() {
|
||||
if len(code) == 5 && course != -1 {
|
||||
fmt.Printf("%d %s\n", course, code)
|
||||
submit_code(course, code)
|
||||
} else if code != "" && course == -1 {
|
||||
fmt.Println("Course code not provided")
|
||||
usage()
|
||||
os.Exit(1)
|
||||
} else if code == "" && course != -1 {
|
||||
fmt.Println("Attendance code not provided")
|
||||
usage()
|
||||
@ -83,5 +79,8 @@ func main() {
|
||||
fmt.Println("Attendance code must be 5 characters long")
|
||||
usage()
|
||||
os.Exit(1)
|
||||
} else if len(code) == 5 && course == -1 {
|
||||
fmt.Println("Checking which course to send the code to")
|
||||
submit_code_sans_course(code)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user