diff --git a/README.md b/README.md index 1f9b063..f39e075 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,5 @@ or LSF Served Fabulously - documentation - tests - webapi -- rename session to client? - wrap errors correctly. run cmd/lsf without an internet connection and get inspired by the standard libary -- use english terms only +- username/password prompt stderr diff --git a/cmd/lsf/main.go b/cmd/lsf/main.go index 41cdbc6..f7432a4 100644 --- a/cmd/lsf/main.go +++ b/cmd/lsf/main.go @@ -46,12 +46,11 @@ func main() { func cmdGrades(cmd *cli.Cmd) { cmd.Before = sessionNeeded cmd.Action = func() { - noten, err := s.Noten() + grades, err := s.Grades() if err != nil { log.Fatal(err) } - fmt.Println("Noten:") - noten.Print() + grades.Print() } } diff --git a/noten.go b/grades.go similarity index 62% rename from noten.go rename to grades.go index 54b4eb0..c7dca49 100644 --- a/noten.go +++ b/grades.go @@ -9,22 +9,23 @@ import ( "github.com/pkg/errors" ) -// Note is a grade with associated data like the related module -type Note struct { - Nr string - Name string - Semester string - Note string - Status string - CPs string - Versuch string +// Grade is a grade with associated data like the related module +type Grade struct { + Nr string + Name string + Term string + Grade string + Status string + Credits string + Try string } -type Noten []*Note +// Grades is an Array of Grade pointers +type Grades []*Grade -func (n *Note) String() string { +func (g *Grade) String() string { var status string - switch n.Status { + switch g.Status { case "angemeldet": status = "⏳ - " case "bestanden": @@ -34,18 +35,19 @@ func (n *Note) String() string { default: status = "❓" } - return fmt.Sprintf("%s%s %s", status, n.Note, n.Name) + return fmt.Sprintf("%s%s %s", status, g.Grade, g.Name) } -func (nn Noten) Print() { - for _, n := range nn { - fmt.Println(n) +// Print prints a clear overview of the grades in the given list +func (gg Grades) Print() { + for _, g := range gg { + fmt.Println(g) } } -// Noten returns a list of the grades of all graded or signed up modules -func (s *Session) Noten() (Noten, error) { - var noten Noten +// Grades returns a list of the grades of all graded or signed up modules +func (s *Session) Grades() (Grades, error) { + var grades Grades client := &http.Client{} url := "https://lsf.hs-worms.de/qisserver/rds?state=notenspiegelStudent&next=list.vm&nextdir=qispos/notenspiegel/student&createInfos=Y&struct=auswahlBaum&nodeID=auswahlBaum%7Cabschluss%3Aabschl%3D05%2Cstgnr%3D1%7Cstudiengang%3Astg%3D938%2Cpversion%3D2018&expand=0&asi=" + s.ASI req, err := http.NewRequest("GET", url, nil) @@ -69,17 +71,17 @@ func (s *Session) Noten() (Noten, error) { vals := row.ChildrenFiltered("td").Map(func(i int, cell *goquery.Selection) string { return strings.TrimSpace(cell.Text()) }) - note := Note{ - Nr: vals[0], - Name: vals[1], - Semester: vals[2], - Note: vals[3], - Status: vals[4], - CPs: vals[5], - Versuch: vals[7], + grade := &Grade{ + Nr: vals[0], + Name: vals[1], + Term: vals[2], + Grade: vals[3], + Status: vals[4], + Credits: vals[5], + Try: vals[7], } - noten = append(noten, ¬e) + grades = append(grades, grade) }) - return noten, nil + return grades, nil }