Skip to content

Commit

Permalink
v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bvp committed Dec 20, 2021
1 parent 8d7adad commit 1855e29
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,33 @@ func (cli *Client) GetMarksPeriods() (periods []Lperiod, err error) {
s.Find("option").Each(func(i int, s2 *goquery.Selection) {
title := strings.TrimSpace(s2.Text())
value, _ := s2.Attr("value")

var resp *http.Response
resp, err = cli.http.Get(fmt.Sprintf("%s%s/note", urlMarksCurrent, value))
if err != nil {
return
}

doc, err := goquery.NewDocumentFromResponse(resp)
if err != nil {
return
}
re := regexp.MustCompile(`(?P<start>(\d{1,2}\s[\p{L}]+\s\d{4}\sг\.)) по (?P<end>(\d{1,2}\s[\p{L}]+\s\d{4}\sг\.))`)
n1 := re.SubexpNames()
result := re.FindStringSubmatch(doc.Find("#content > h3").First().Text())
m := map[string]string{}
for i, n := range result {
m[n1[i]] = n
}

period := Lperiod{
SchoolID: cli.CurrentInfo.SchoolID,
SYear: cli.CurrentInfo.EduYearStart,
EYear: cli.CurrentInfo.EduYearEnd,
Name: title,
Period: value,
Start: russiantime.ParseDateString(m["start"]),
End: russiantime.ParseDateString(m["end"]),
}
periods = append(periods, period)
})
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestClient_GetMarksPeriods(t *testing.T) {
t.Logf(":: size - %d", len(periods))
if DEBUG {
for _, p := range periods {
t.Logf(":: %d-%d: %s - %s", p.SYear, p.EYear, p.Name, p.Period)
t.Logf(":: %d-%d: %s - %s (%s - %s)", p.SYear, p.EYear, p.Name, p.Period, p.Start.Format("2006.01.02"), p.End.Format("2006.01.02"))
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ type Homework struct {

// Lperiod struct
type Lperiod struct {
SchoolID int64 `json:"schoolId" xorm:"'school_id'"`
SYear int `json:"start_year"`
EYear int `json:"end_year"`
Name string `json:"name"`
Period string `json:"period"`
SchoolID int64 `json:"schoolId" xorm:"'school_id'"`
SYear int `json:"start_year"`
EYear int `json:"end_year"`
Name string `json:"name"`
Period string `json:"period"`
Start time.Time `json:"start"`
End time.Time `json:"end"`
}

func (p Lperiod) String() string {
Expand Down

0 comments on commit 1855e29

Please sign in to comment.