mirror of
https://codeberg.org/flpolyaplus/aplus.git
synced 2024-11-22 01:10:29 -05:00
83 lines
1.8 KiB
Go
83 lines
1.8 KiB
Go
|
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))
|
||
|
}
|