-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (62 loc) · 1.91 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"log"
"os"
"time"
"github.com/joho/godotenv"
"github.com/nerodesu017/lambdalabs-sniper/src/constants"
"github.com/nerodesu017/lambdalabs-sniper/src/logged_in"
"github.com/nerodesu017/lambdalabs-sniper/src/monitor"
"github.com/nerodesu017/lambdalabs-sniper/src/notifier"
"github.com/nerodesu017/lambdalabs-sniper/src/utils"
)
func main() {
log_file, err := os.OpenFile("default.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error when opening log file: %v\n", err)
}
defer log_file.Close()
log.SetOutput(log_file)
log.Printf("Starting monitor... (Sniper not yet implemented)")
err = godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file: %v\n", err)
}
log.Printf("Successfully imported .env file!")
email, err:= logged_in.GetEmail(os.Getenv("SESSION_ID"))
if err != nil {
log.Fatalf("error when logging in")
}
log.Printf("Connected as '%s'\n", email)
discord_notifier := notifier.Discord_notifier{
Webhook_url: os.Getenv("DISCORD_WEBHOOK"),
}
// array for keeping track of last known available GPUs
last_known_available_gpus := make([]*constants.GPU, 0)
for ;; {
new_found_gpus, err := monitor.FindAvailable()
if err != nil {
log.Fatalf("error when monitoring: %v\n", err)
}
diff_gpus := utils.GetGPUDiff(last_known_available_gpus, new_found_gpus)
log.Printf("New gpus: ")
for i, gpu := range diff_gpus {
if i == len(diff_gpus) - 1 {
log.Println(gpu.Name)
} else {
log.Printf("%s, \n", gpu.Name)
}
}
if len(diff_gpus) != 0 {
err = discord_notifier.Notify(diff_gpus)
if err != nil {
log.Fatalf("error when sending webhook: %v\n", err)
}
}
last_known_available_gpus = new_found_gpus
miliseconds := time.Duration(utils.GetRandSleepTimeInMs(3000, 5000))
log.Printf("Sleeping for %d miliseconds\n", miliseconds)
// every 3-5 seconds
time.Sleep(time.Millisecond * miliseconds)
}
}