Files
schedule-poll/internal/schedule/poll.go

50 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package schedule
import (
"fmt"
"log"
"os"
"git.inkling.su/mrqiz/schedule-poll/internal/config"
"git.inkling.su/mrqiz/schedule-poll/internal/telegram"
)
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,
days,
siteUrl)
err = telegram.SendMessage(config.AppConfig.Telegram.ChatId, msg)
if err != nil {
log.Panicln("Unable to send message: ", err)
}
os.WriteFile(flagFilePath, []byte(msg), os.FileMode(0777))
log.Printf("Found %d days", len(week.Days))
}
}