Temp timezone fix #11
2 changed files with 20 additions and 14 deletions
|
|
@ -12,6 +12,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
|
@ -108,6 +109,12 @@ func decrypt(encrypted string) (string, error) {
|
|||
func saveAccount(userID, username, password string) error {
|
||||
var accounts []Account
|
||||
|
||||
// Ensure the accounts directory exists
|
||||
accountsDir := filepath.Dir(accountsFile)
|
||||
if err := os.MkdirAll(accountsDir, 0755); err != nil {
|
||||
return fmt.Errorf("failed to create accounts directory: %v", err)
|
||||
}
|
||||
|
||||
// Load existing accounts if file exists
|
||||
if data, err := os.ReadFile(accountsFile); err == nil && len(data) > 0 {
|
||||
_ = json.Unmarshal(data, &accounts)
|
||||
|
|
|
|||
27
main.go
27
main.go
|
|
@ -101,7 +101,6 @@ func init() {
|
|||
}
|
||||
|
||||
func main() {
|
||||
|
||||
godotenv.Load(".env")
|
||||
// Untis.Main() //starting API calls function| happens in schedule func
|
||||
// Run()
|
||||
|
|
@ -316,7 +315,7 @@ func Run(userID string) {
|
|||
nowOld := time.Now()
|
||||
nowOld = nowOld.Add(1 * time.Hour)
|
||||
now := nowOld.Format("15:04")
|
||||
|
||||
|
||||
nextTime, room, foundRoom := NextRoomForTime(roomByStartTime, now)
|
||||
if !foundRoom {
|
||||
return // No upcoming lessons
|
||||
|
|
@ -355,10 +354,10 @@ func NextRoomForTime(roomByStartTime map[string]string, current string) (string,
|
|||
if err != nil {
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
|
||||
// Calculate 30 minutes from now
|
||||
thirtyMinutesLater := now.Add(30 * time.Minute)
|
||||
|
||||
|
||||
var times []time.Time
|
||||
timeToStr := make(map[time.Time]string)
|
||||
for t := range roomByStartTime {
|
||||
|
|
@ -372,11 +371,11 @@ func NextRoomForTime(roomByStartTime map[string]string, current string) (string,
|
|||
timeToStr[parsed] = t
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if len(times) == 0 {
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
|
||||
sort.Slice(times, func(i, j int) bool { return times[i].Before(times[j]) })
|
||||
// Return the first (earliest) room within the 30-minute window
|
||||
return timeToStr[times[0]], roomByStartTime[timeToStr[times[0]]], true
|
||||
|
|
@ -388,10 +387,10 @@ func NextSubjectForTime(subjectByStartTime map[string]string, current string) (s
|
|||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
||||
// Calculate 30 minutes from now
|
||||
thirtyMinutesLater := now.Add(30 * time.Minute)
|
||||
|
||||
|
||||
var times []time.Time
|
||||
timeToStr := make(map[time.Time]string)
|
||||
for t := range subjectByStartTime {
|
||||
|
|
@ -405,11 +404,11 @@ func NextSubjectForTime(subjectByStartTime map[string]string, current string) (s
|
|||
timeToStr[parsed] = t
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if len(times) == 0 {
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
||||
sort.Slice(times, func(i, j int) bool { return times[i].Before(times[j]) })
|
||||
// Return the first (earliest) subject within the 30-minute window
|
||||
return subjectByStartTime[timeToStr[times[0]]], true
|
||||
|
|
@ -421,10 +420,10 @@ func NextCodeForTime(codeByStartTime map[string]string, current string) (string,
|
|||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
||||
// Calculate 30 minutes from now
|
||||
thirtyMinutesLater := now.Add(30 * time.Minute)
|
||||
|
||||
|
||||
var times []time.Time
|
||||
timeToStr := make(map[time.Time]string)
|
||||
for t := range codeByStartTime {
|
||||
|
|
@ -438,11 +437,11 @@ func NextCodeForTime(codeByStartTime map[string]string, current string) (string,
|
|||
timeToStr[parsed] = t
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if len(times) == 0 {
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
||||
sort.Slice(times, func(i, j int) bool { return times[i].Before(times[j]) })
|
||||
// Return the first (earliest) code within the 30-minute window
|
||||
return codeByStartTime[timeToStr[times[0]]], true
|
||||
|
|
|
|||
Loading…
Reference in a new issue