From 909783373c746d2495a4ced0b69fabde9075aacd Mon Sep 17 00:00:00 2001 From: Jannover5000r Date: Tue, 28 Oct 2025 08:42:22 +0100 Subject: [PATCH] works? --- Untis/Untis.go | 7 +++---- main.go | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Untis/Untis.go b/Untis/Untis.go index 7b3faf9..407ce16 100644 --- a/Untis/Untis.go +++ b/Untis/Untis.go @@ -32,9 +32,8 @@ type LoginResponse struct { var Url = "https://thalia.webuntis.com/WebUntis/jsonrpc.do?school=Mons_Tabor" -//var Password = os.Getenv("UNTIS_PASSWORD") -//var USERS = os.Getenv("UNTIS_USER") - +// 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 } diff --git a/main.go b/main.go index 95c0d5d..3d9223a 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "sort" "syscall" "time" + Untis "untislogger/Untis" BotStart "untislogger/Botrun" @@ -53,9 +54,9 @@ func init() { func main() { godotenv.Load(".env") - //Untis.Main() //starting API calls function| happens in schedule func - //Run() - //Starts logging the timetable for each new Lesson and logs changes + // Untis.Main() //starting API calls function| happens in schedule func + // Run() + // Starts logging the timetable for each new Lesson and logs changes go BotStart.Start() scheduleTimetableUpdate() @@ -63,12 +64,13 @@ func main() { signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) log.Println("Program is running. Press Ctrl+C to stop.") - //Start logging - //Run() + // Start logging + // Run() // Block until we receive a signal <-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 { -- 2.45.2