feat: Basic polling
This commit is contained in:
44
internal/schedule/poll.go
Normal file
44
internal/schedule/poll.go
Normal file
@ -0,0 +1,44 @@
|
||||
package schedule
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.inkling.su/mrqiz/schedule-poll/internal/config"
|
||||
)
|
||||
|
||||
func PollSchedule() {
|
||||
flagFilePath := config.AppConfig.FlagfilePath
|
||||
|
||||
if _, fileErr := os.Stat(flagFilePath); fileErr == nil {
|
||||
return
|
||||
}
|
||||
|
||||
facultyId := config.AppConfig.Schedule.FacultyId
|
||||
groupId := config.AppConfig.Schedule.GroupId
|
||||
date := config.AppConfig.Schedule.StartDate
|
||||
|
||||
week, err := GetWeek(groupId, date)
|
||||
|
||||
if err != nil {
|
||||
log.Panicln("Failed to get week data", err)
|
||||
}
|
||||
|
||||
days := len(week.Days)
|
||||
|
||||
if days != 0 {
|
||||
siteUrl := GetScheduleUrl(facultyId, groupId, date)
|
||||
msg := fmt.Sprintf(
|
||||
"❗ Опубликовано расписание на новый семестр!\n\n"+
|
||||
"Появились занятия на неделе с %s\n"+
|
||||
"Доступно дней: %d\n\n"+
|
||||
"%s\n",
|
||||
date,
|
||||
len(week.Days),
|
||||
siteUrl)
|
||||
|
||||
os.WriteFile(flagFilePath, []byte(msg), os.FileMode(0777))
|
||||
log.Printf("Found %d days", len(week.Days))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user