57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package parser
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/erizocosmico/go-ics"
|
|
)
|
|
|
|
type Lesson struct {
|
|
Number string
|
|
TimeStart time.Time
|
|
TimeMsg string
|
|
Name string
|
|
User string
|
|
Place string
|
|
}
|
|
|
|
func ParseByDay(day string) []Lesson {
|
|
return selectLessonsByDay(parse(), day)
|
|
}
|
|
|
|
func parse() []Lesson {
|
|
link := "https://www.asu.ru/timetable/students/12/2129440415/?file=2129440415.ics"
|
|
calendar, err := ics.ParseCalendar(link, 0, nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var lessons []Lesson
|
|
for _, event := range calendar.Events {
|
|
l := Lesson{
|
|
Number: "",
|
|
TimeStart: event.Start,
|
|
TimeMsg: event.Start.Format("15:04") + " - " + event.End.Format("15:04"),
|
|
Name: event.Summary,
|
|
User: event.Description,
|
|
Place: event.Location,
|
|
}
|
|
if l.Place == "" {
|
|
l.Place = "не приходи"
|
|
}
|
|
lessons = append(lessons, l)
|
|
}
|
|
return lessons
|
|
}
|
|
|
|
func selectLessonsByDay(schedule []Lesson, day string) []Lesson {
|
|
var todayLessons []Lesson
|
|
for _, l := range schedule {
|
|
if day == "" || strings.Contains(l.TimeStart.String(), day) {
|
|
todayLessons = append(todayLessons, l)
|
|
}
|
|
}
|
|
return todayLessons
|
|
}
|