86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
package lsf
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
"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
|
|
}
|
|
|
|
type Noten []*Note
|
|
|
|
func (n *Note) String() string {
|
|
var status string
|
|
switch n.Status {
|
|
case "angemeldet":
|
|
status = "⏳ - "
|
|
case "bestanden":
|
|
status = "✔ "
|
|
case "nicht bestanden":
|
|
status = "✖ "
|
|
default:
|
|
status = "❓"
|
|
}
|
|
return fmt.Sprintf("%s%s %s", status, n.Note, n.Name)
|
|
}
|
|
|
|
func (nn Noten) Print() {
|
|
for _, n := range nn {
|
|
fmt.Println(n)
|
|
}
|
|
}
|
|
|
|
// Noten returns a list of the grades of all graded or signed up modules
|
|
func (s *Session) Noten() (Noten, error) {
|
|
var noten Noten
|
|
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)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not prepare the request")
|
|
}
|
|
req.Header.Add("Cookie", fmt.Sprintf("JSESSIONID=%s", s.SID))
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not do the request")
|
|
}
|
|
doc, err := goquery.NewDocumentFromResponse(resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Find all tables. The last one contains the grades. Get all children rows.
|
|
rows := doc.Find("table").Last().Find("tr")
|
|
// The first three are the header, the average mark and a divider. So lets ignore them.
|
|
rows.Slice(3, rows.Length()).Each(func(_ int, row *goquery.Selection) {
|
|
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],
|
|
}
|
|
noten = append(noten, ¬e)
|
|
})
|
|
|
|
return noten, nil
|
|
}
|