From 711f2d2e7b4888e7c087bde7519439fe031e74c5 Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 17 Oct 2023 00:05:00 +0200 Subject: [PATCH] fix: Open account login flow rework --- cmd/tweeter.go | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/cmd/tweeter.go b/cmd/tweeter.go index 1bbd295..e9d03b5 100644 --- a/cmd/tweeter.go +++ b/cmd/tweeter.go @@ -100,26 +100,33 @@ func Run() { log.Println("We're already logged in, skipping login...") } else { scraper.ClearCookies() - err = scraper.Login(config.Username, config.Password) - if err != nil { - log.Printf("An error occurred during scraper login: %s\n", err.Error()) + if len(config.Username) > 0 { + err = scraper.Login(config.Username, config.Password) + if err != nil { + log.Fatalf("An error occurred during scraper login: %s\n", err.Error()) + } else { + log.Printf("New Login - Saving cookies to %s\n", cookiePath) + js, jsonErr := json.Marshal(scraper.GetCookies()) + if jsonErr != nil { + log.Fatalf("An error occurred during cookie serialization: %s\n", jsonErr.Error()) + } + f, fErr := os.Create(cookiePath) + if fErr != nil { + log.Fatalf("Failed to create cookie file at %s with the following error: %s\n", cookiePath, fErr.Error()) + } + f.Write(js) + writeErr := f.Close() + if writeErr != nil { + log.Fatalf("An error occurred on closing cookie file: %s\n", writeErr.Error()) + } + } + } else { log.Println("Trying open account login... ") err = scraper.LoginOpenAccount() if err != nil { log.Fatalf("An error occurred during scraper login: %s\n", err.Error()) } defer scraper.Logout() - } else { - log.Printf("New Login - Saving cookies to %s\n", cookiePath) - js, jsonErr := json.Marshal(scraper.GetCookies()) - if jsonErr != nil { - log.Fatalf("An error occurred during cookie serialization: %s\n", jsonErr.Error()) - } - f, fErr := os.Create(cookiePath) - if fErr != nil { - log.Fatalf("Failed to create cookie file at %s with the following error: %s\n", cookiePath, fErr.Error()) - } - f.Write(js) } }