summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go54
1 files changed, 52 insertions, 2 deletions
diff --git a/main.go b/main.go
index eb88b8d..63b978f 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ import (
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 "net/http" 7 "net/http"
8 "net/url"
8 "strings" 9 "strings"
9) 10)
10 11
@@ -49,6 +50,48 @@ func get_course_ids(canvas_courses []CanvasCourse) []uint64 {
49 return courses 50 return courses
50} 51}
51 52
53// parseForm extracts form fields and values from the given HTML form string.
54func parse_form(form_html string) url.Values {
55 form_values := make(url.Values)
56 inputs := strings.Split(form_html, "<input")
57
58 for _, input := range inputs {
59 // Extract field name and value
60 name := extract_attribute(input, "name")
61 value := extract_attribute(input, "value")
62
63 if name != "" {
64 form_values.Add(name, value)
65 }
66 }
67
68 return form_values
69}
70
71func extract_attribute(input string, attribute string) string {
72 start := strings.Index(input, attribute+"=\"")
73 if start == -1 {
74 start = strings.Index(input, attribute+"='")
75 }
76
77 if start == -1 {
78 return ""
79 }
80
81 start += len(attribute) + 2
82
83 end := strings.Index(input[start:], "\"")
84 if end == -1 {
85 end = strings.Index(input[start:], "'")
86 }
87
88 if end == -1 {
89 return ""
90 }
91
92 return input[start : start+end]
93}
94
52func main() { 95func main() {
53 client := http.Client{ 96 client := http.Client{
54 CheckRedirect: func(req *http.Request, via []*http.Request) error { 97 CheckRedirect: func(req *http.Request, via []*http.Request) error {
@@ -59,7 +102,7 @@ func main() {
59 102
60 // https://canvas.instructure.com/api/v1/courses?access_token={}&per_page=100", canvas_token 103 // https://canvas.instructure.com/api/v1/courses?access_token={}&per_page=100", canvas_token
61 base_link := "https://floridapolytechnic.instructure.com/api/v1" 104 base_link := "https://floridapolytechnic.instructure.com/api/v1"
62 token := "token here" 105 token := "token"
63 106
64 // course selection by user happens below 107 // course selection by user happens below
65 //favorites := fmt.Sprintf("%s/users/self/favorites/courses?access_token=%s&per_page=100", base_link, token) 108 //favorites := fmt.Sprintf("%s/users/self/favorites/courses?access_token=%s&per_page=100", base_link, token)
@@ -100,8 +143,15 @@ func main() {
100 form_end := strings.Index(body_str, "</form>") + 7 143 form_end := strings.Index(body_str, "</form>") + 7
101 form_html := body[form_start:form_end] 144 form_html := body[form_start:form_end]
102 145
103 fmt.Println(string(form_html)) 146 form := string(form_html)
147 fmt.Println(form)
104 148
149 form_values := parse_form(form)
150
151 fmt.Println("Form Values:")
152 for key, values := range form_values {
153 fmt.Printf("%s: %s\n", key, values)
154 }
105} 155}
106 156
107/* 157/*