works? #5

Merged
Jannover5000r merged 2 commits from feat/implement-timetable-fetching into main 2025-10-28 08:53:49 +01:00
2 changed files with 18 additions and 13 deletions
Showing only changes of commit 909783373c - Show all commits

View file

@ -34,7 +34,6 @@ var Url = "https://thalia.webuntis.com/WebUntis/jsonrpc.do?school=Mons_Tabor"
// var Password = os.Getenv("UNTIS_PASSWORD")
// var USERS = os.Getenv("UNTIS_USER")
func Main(user, password, userID string) {
godotenv.Load("../.env")
cookies, err := Auth(user, password, userID)
@ -85,7 +84,7 @@ func Auth(user, password, userID string) ([]*http.Cookie, error) {
if userID != "" {
loginFile = "login_" + userID + ".json"
}
if err := os.WriteFile(loginFile, data, 0644); err != nil {
if err := os.WriteFile(loginFile, data, 0o644); err != nil {
return nil, err
}

14
main.go
View file

@ -12,6 +12,7 @@ import (
"sort"
"syscall"
"time"
Untis "untislogger/Untis"
BotStart "untislogger/Botrun"
@ -69,6 +70,7 @@ func main() {
<-sigChan
log.Println("Shutting down...")
}
func isScheduledTime(now time.Time) bool {
scheduled := []string{"07:45", "08:35", "09:35", "10:25", "11:25", "12:15", "13:45", "14:25"}
current := now.Format("15:04")
@ -79,6 +81,7 @@ func isScheduledTime(now time.Time) bool {
}
return false
}
func scheduleTimetableUpdate() {
prevData := make(map[string][]byte)
@ -109,7 +112,7 @@ func scheduleTimetableUpdate() {
// Check for changes
timetableFile := fmt.Sprintf("timetableFilled_%s.json", acc.UserID)
if acc.UserID == "default" {
timetableFile = "timetableFilled.json"
timetableFile = "timetableFilled_default.json"
}
data, err := os.ReadFile(timetableFile)
if err != nil {
@ -166,7 +169,7 @@ func startMinuteTicker(f func()) {
}
func Run(userID string) {
timetableFile := "timetableFilled.json"
timetableFile := "timetableFilled_default.json"
if userID != "default" {
timetableFile = fmt.Sprintf("timetableFilled_%s.json", userID)
}
@ -236,6 +239,7 @@ func NextRoomForTime(roomByStartTime map[string]string, current string) (string,
}
return "", "", false
}
func NextSubjectForTime(subjectByStartTime map[string]string, current string) (string, bool) {
layout := "15:04"
now, err := time.Parse(layout, current)
@ -260,8 +264,8 @@ func NextSubjectForTime(subjectByStartTime map[string]string, current string) (s
}
return "", false
}
func NextCodeForTime(codeByStartTime map[string]string, current string) (string, bool) {
func NextCodeForTime(codeByStartTime map[string]string, current string) (string, bool) {
layout := "15:04"
now, err := time.Parse(layout, current)
if err != nil {
@ -284,8 +288,8 @@ func NextCodeForTime(codeByStartTime map[string]string, current string) (string,
}
}
return "", false
}
func MapTimeToRoom(path string) (map[string]string, error) {
data, err := os.ReadFile(path)
if err != nil {
@ -304,6 +308,7 @@ func MapTimeToRoom(path string) (map[string]string, error) {
}
return roomByStartTime, nil
}
func MapTimeToCode(path string) (map[string]string, error) {
data, err := os.ReadFile(path)
if err != nil {
@ -324,6 +329,7 @@ func MapTimeToCode(path string) (map[string]string, error) {
}
return codeByStartTime, nil
}
func MapTimeToSubject(path string) (map[string]string, error) {
data, err := os.ReadFile(path)
if err != nil {