Updated Credentials Storage
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/chromedp/chromedp"
|
||||
)
|
||||
|
||||
const (
|
||||
webUrl = "https://gisem.dei.estg.ipleiria.pt"
|
||||
)
|
||||
|
||||
var waitTime int
|
||||
|
||||
func main() {
|
||||
//* Parse the flags
|
||||
wait, headless, err := parseFlags()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse flags: %v", err)
|
||||
}
|
||||
waitTime = wait
|
||||
|
||||
fmt.Println("Waiting time:", waitTime)
|
||||
|
||||
//* Welcome message
|
||||
welcomeMessage()
|
||||
|
||||
creds, err := getCreds()
|
||||
if err != nil {
|
||||
// If the credentials file doesn't exist, prompt for credentials
|
||||
if err.Error() == "credentials file not found: stat "+credFile+": no such file or directory" {
|
||||
// The file doesn't exist, create it by prompting for credentials
|
||||
creds, err = promptAndSaveCreds(credFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get credentials: %v", err)
|
||||
}
|
||||
} else {
|
||||
log.Fatalf("Failed to get credentials: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
opts := append(chromedp.DefaultExecAllocatorOptions[:],
|
||||
chromedp.Flag("headless", headless), // Disable headless mode
|
||||
chromedp.Flag("disable-gpu", headless), // Enable GPU
|
||||
chromedp.Flag("start-maximized", !headless), // Start maximized
|
||||
)
|
||||
|
||||
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
|
||||
defer cancel()
|
||||
|
||||
ctx, cancel := chromedp.NewContext(allocCtx)
|
||||
defer cancel()
|
||||
|
||||
//* Navigate to the website
|
||||
if err := chromedp.Run(ctx, chromedp.Navigate(webUrl)); err != nil {
|
||||
log.Fatalf("Failed to navigate: %v", err)
|
||||
}
|
||||
|
||||
//* Check if there's a login button
|
||||
var isVisible bool
|
||||
if err := chromedp.Run(ctx, chromedp.Tasks{
|
||||
chromedp.WaitVisible(loginButton),
|
||||
chromedp.Evaluate(fmt.Sprintf("document.querySelector('%s').offsetParent !== null", loginButton), &isVisible),
|
||||
}); err != nil {
|
||||
log.Fatalf("Failed to evaluate: %v", err)
|
||||
}
|
||||
|
||||
if isVisible {
|
||||
log.Println("Logging in...")
|
||||
if err := login(ctx, creds); err != nil {
|
||||
log.Fatalf("Failed to login: %v", err)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
log.Println("Waiting for activation...")
|
||||
if err := marcarPresenca(ctx); err != nil {
|
||||
log.Fatalf("Failed to mark presence: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user