From aa16b741d54325527eb6bea451cb24526551ab52 Mon Sep 17 00:00:00 2001 From: Juan Roig Date: Tue, 14 Nov 2023 04:23:18 -0500 Subject: [PATCH] Add list courses functions, remove unnecessary functions, update README. --- README.md | 18 ++++++++++++++---- aplus.go | 3 ++- canvas.go | 31 ++++++++++++++----------------- main.go | 1 + 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 5735615..db117a3 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,23 @@ # 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 --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 aplus --code +### Enter code for a specified course +aplus -c --course +aplus --code --course \ No newline at end of file diff --git a/aplus.go b/aplus.go index 18beddb..427e2bf 100644 --- a/aplus.go +++ b/aplus.go @@ -11,7 +11,8 @@ import ( ) 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) resp, _ := client.Get(aplus) diff --git a/canvas.go b/canvas.go index 3aa8050..c31265a 100644 --- a/canvas.go +++ b/canvas.go @@ -14,7 +14,7 @@ import ( func initialize() { base_link = "https://floridapolytechnic.instructure.com/api/v1" token = os.Getenv("CANVAS_API_KEY") - + external_tools_code = 913 jar, _ := cookiejar.New(&cookiejar.Options{ PublicSuffixList: publicsuffix.List, }) @@ -48,27 +48,24 @@ func get_courses(token string, link string, client http.Client) []CanvasCourse { return canvas_courses } -// Need to change this to grab both ID and name, return as pairs. -func get_course_id_name_pair(canvas_courses []CanvasCourse) []uint64 { - var courses []uint64 +func list_all_courses() { + all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link, token) + + canvas_courses := get_courses(token, all_courses, client) for _, course := range canvas_courses { - courses = append(courses, course.ID%10000) + fmt.Printf("%s, %d\n", course.Name, course.ID%10000) } - return courses } -/* -func select_course() int { +func list_favorite_courses() { + // course selection by user happens below 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) - var course_ids []uint64 - course_ids = get_course_ids(canvas_courses) - //selected := 1 // course_ids[selected] - // course selection by user happens above - return 0 + + canvas_courses := get_courses(token, favorites, client) + + for _, course := range canvas_courses { + fmt.Printf("%s, %d\n", course.Name, course.ID%10000) + } } -*/ diff --git a/main.go b/main.go index 8f669e1..eb602e6 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( var base_link string var token string +var external_tools_code int var client http.Client func main() {