Add list courses functions, remove unnecessary functions, update README.

This commit is contained in:
Juan Roig 2023-11-14 04:23:18 -05:00
parent dc7d8df66b
commit aa16b741d5
4 changed files with 31 additions and 22 deletions

View File

@ -1,13 +1,23 @@
# aplus # aplus
aplus cli This is an aplus cli utility created for students at Florida Polytechnic University to submit their aplus codes through the CLI.
In time, we intend to generalize this utility to all universities.
In the meantime however, any students from other universities wishing to use the utility may change the base_link and external_tools_code (you see this in the URL when you navigate to Aplus attendance within your course) variables.
# Usage ## Usage
# Launch interactive prompt ### List all courses and canvas course codes
aplus aplus
aplus --list-courses
aplus -l
# Enter code immediately ### List favorite courses and canvas course codes
aplus --list-favorites
### Enter code immediately for an active code
aplus -c <code> aplus -c <code>
aplus --code <code> aplus --code <code>
### Enter code for a specified course
aplus -c <code> --course <course_code>
aplus --code <code> --course <course_code>

View File

@ -11,7 +11,8 @@ import (
) )
func launch_aplus(course_code int) { func launch_aplus(course_code int) {
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, course_code, token) // 7329 always works aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=%d&access_token=%s",
base_link, course_code, external_tools_code, token)
aplus := get_aplus(token, aplus_link, client) aplus := get_aplus(token, aplus_link, client)
resp, _ := client.Get(aplus) resp, _ := client.Get(aplus)

View File

@ -14,7 +14,7 @@ import (
func initialize() { func initialize() {
base_link = "https://floridapolytechnic.instructure.com/api/v1" base_link = "https://floridapolytechnic.instructure.com/api/v1"
token = os.Getenv("CANVAS_API_KEY") token = os.Getenv("CANVAS_API_KEY")
external_tools_code = 913
jar, _ := cookiejar.New(&cookiejar.Options{ jar, _ := cookiejar.New(&cookiejar.Options{
PublicSuffixList: publicsuffix.List, PublicSuffixList: publicsuffix.List,
}) })
@ -48,27 +48,24 @@ func get_courses(token string, link string, client http.Client) []CanvasCourse {
return canvas_courses return canvas_courses
} }
// Need to change this to grab both ID and name, return as pairs. func list_all_courses() {
func get_course_id_name_pair(canvas_courses []CanvasCourse) []uint64 { all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link, token)
var courses []uint64
canvas_courses := get_courses(token, all_courses, client)
for _, course := range canvas_courses { for _, course := range canvas_courses {
courses = append(courses, course.ID%10000) fmt.Printf("%s, %d\n", course.Name, course.ID%10000)
} }
return courses
} }
/* func list_favorite_courses() {
func select_course() int {
// course selection by user happens below // course selection by user happens below
favorites := fmt.Sprintf("%s/users/self/favorites/courses?access_token=%s&per_page=100", base_link, token) favorites := fmt.Sprintf("%s/users/self/favorites/courses?access_token=%s&per_page=100", base_link, token)
all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link, token)
var canvas_courses []CanvasCourse canvas_courses := get_courses(token, favorites, client)
canvas_courses = get_courses(token, favorites, client)
var course_ids []uint64 for _, course := range canvas_courses {
course_ids = get_course_ids(canvas_courses) fmt.Printf("%s, %d\n", course.Name, course.ID%10000)
//selected := 1 // course_ids[selected] }
// course selection by user happens above
return 0
} }
*/

View File

@ -6,6 +6,7 @@ import (
var base_link string var base_link string
var token string var token string
var external_tools_code int
var client http.Client var client http.Client
func main() { func main() {