From 41a98cfe6012afc3bb02a027bdf04c8a9fa422ad Mon Sep 17 00:00:00 2001 From: Juan Roig Date: Fri, 27 Oct 2023 19:02:38 -0400 Subject: [PATCH] first commit --- file.html | 213 +++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 3 + main.go | 82 +++++++++++++++++++++ structs.go | 56 ++++++++++++++ 4 files changed, 354 insertions(+) create mode 100644 file.html create mode 100644 go.mod create mode 100644 main.go create mode 100644 structs.go diff --git a/file.html b/file.html new file mode 100644 index 0000000..9a0d8cc --- /dev/null +++ b/file.html @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + aPlus+ Attendance + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ This tool needs to be loaded in a new browser window +
+ +
+
+ +
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a5570a0 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module codeberg.org/flpolyaplus/aplus + +go 1.21.3 diff --git a/main.go b/main.go new file mode 100644 index 0000000..dd088d7 --- /dev/null +++ b/main.go @@ -0,0 +1,82 @@ +package main + +import ( + "encoding/json" + "fmt" + "io" + "net/http" +) + +func get_courses(token string, link string) []CanvasCourse { + resp, err := http.Get(link) + if err != nil { + // handle error + } + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + + var canvas_courses []CanvasCourse + err2 := json.Unmarshal(body, &canvas_courses) + if err2 != nil { + fmt.Println(err2) + return nil + } + + return canvas_courses +} + +func get_aplus(token string, link string) string { + resp, err := http.Get(link) + + if err != nil { + // handle error + } + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + var aplus Aplus + json.Unmarshal(body, &aplus) + + return aplus.URL +} + +func get_course_ids(canvas_courses []CanvasCourse) []uint64 { + var courses []uint64 + + for _, course := range canvas_courses { + courses = append(courses, course.ID%10000) + } + return courses +} + +func main() { + + // https://canvas.instructure.com/api/v1/courses?access_token={}&per_page=100", canvas_token + base_link := "https://floridapolytechnic.instructure.com/api/v1" + token := "instructure api key" + //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) + //var course_ids []uint64 + //course_ids = get_course_ids(canvas_courses) + + //selected := 1 // course_ids[selected] + aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works + var aplus string + aplus = get_aplus(token, aplus_link) + fmt.Println(aplus) + + resp, err := http.Get(aplus) + + if err != nil { + // handle error + } + + //fmt.Println(resp) + + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + + fmt.Println(string(body)) +} diff --git a/structs.go b/structs.go new file mode 100644 index 0000000..bf75787 --- /dev/null +++ b/structs.go @@ -0,0 +1,56 @@ +package main + +import "time" + +type Aplus struct { + URL string `json:"url"` +} + +type CanvasCourse struct { + ID uint64 `json:"id"` + Name string `json:"name"` + AccountID uint64 `json:"account_id"` + UUID string `json:"uuid"` + StartAt *time.Time `json:"start_at,omitempty"` + GradingStandardID *uint64 `json:"grading_standard_id,omitempty"` + IsPublic bool `json:"is_public"` + CreatedAt time.Time `json:"created_at"` + CourseCode string `json:"course_code"` + DefaultView string `json:"default_view"` + RootAccountID uint64 `json:"root_account_id"` + EnrollmentTermID uint64 `json:"enrollment_term_id"` + License string `json:"license"` + GradePassbackSetting *string `json:"grade_passback_setting,omitempty"` + EndAt *time.Time `json:"end_at,omitempty"` + PublicSyllabus bool `json:"public_syllabus"` + PublicSyllabusToAuth bool `json:"public_syllabus_to_auth"` + StorageQuotaMB uint64 `json:"storage_quota_mb"` + IsPublicToAuthUsers bool `json:"is_public_to_auth_users"` + HomeroomCourse bool `json:"homeroom_course"` + CourseColor *string `json:"course_color,omitempty"` + FriendlyName *string `json:"friendly_name,omitempty"` + ApplyAssignmentGroupWeights bool `json:"apply_assignment_group_weights"` + Locale string `json:"locale"` + Calendar Calendar `json:"calendar"` + TimeZone string `json:"time_zone"` + Blueprint bool `json:"blueprint"` + Template bool `json:"template"` + Enrollments []Enrollment `json:"enrollments"` + HideFinalGrades bool `json:"hide_final_grades"` + WorkflowState string `json:"workflow_state"` + RestrictEnrollmentsToCourseDates bool `json:"restrict_enrollments_to_course_dates"` + OverriddenCourseVisibility string `json:"overridden_course_visibility"` +} + +type Calendar struct { + Ics string `json:"ics"` +} + +type Enrollment struct { + Type string `json:"type_"` + Role string `json:"role"` + RoleID uint64 `json:"role_id"` + UserID uint64 `json:"user_id"` + EnrollmentState string `json:"enrollment_state"` + LimitPrivilegesToCourseSection bool `json:"limit_privileges_to_course_section"` +}