This commit is contained in:
Jannover5000r 2025-10-28 08:42:22 +01:00
parent 8b42761cf0
commit 909783373c
2 changed files with 18 additions and 13 deletions

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 Password = os.Getenv("UNTIS_PASSWORD")
// var USERS = os.Getenv("UNTIS_USER") // var USERS = os.Getenv("UNTIS_USER")
func Main(user, password, userID string) { func Main(user, password, userID string) {
godotenv.Load("../.env") godotenv.Load("../.env")
cookies, err := Auth(user, password, userID) cookies, err := Auth(user, password, userID)
@ -85,7 +84,7 @@ func Auth(user, password, userID string) ([]*http.Cookie, error) {
if userID != "" { if userID != "" {
loginFile = "login_" + userID + ".json" 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 return nil, err
} }

14
main.go
View file

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