diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-08 23:04:51 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-08 23:04:51 +0200 |
| commit | 5ee4d7a6020e32159e735ff9e5b38be5da6bfe9c (patch) | |
| tree | cabe16c43c3ffa4a6f55c2c3095b30bfc809aa9f /internal/platforms/linkedin | |
| parent | 9b14c12e0ccd5c96dd9f17d1b20fe134308d2184 (diff) | |
dont use logger but color outputter
Diffstat (limited to 'internal/platforms/linkedin')
| -rw-r--r-- | internal/platforms/linkedin/linkedin.go | 8 | ||||
| -rw-r--r-- | internal/platforms/linkedin/oauth2/oauth2.go | 14 | ||||
| -rw-r--r-- | internal/platforms/linkedin/preview.go | 6 |
3 files changed, 15 insertions, 13 deletions
diff --git a/internal/platforms/linkedin/linkedin.go b/internal/platforms/linkedin/linkedin.go index 1d57a9e..283ab14 100644 --- a/internal/platforms/linkedin/linkedin.go +++ b/internal/platforms/linkedin/linkedin.go @@ -7,10 +7,10 @@ import ( "errors" "fmt" "io" - "log" "net/http" "time" + "codeberg.org/snonux/gos/internal/colour" "codeberg.org/snonux/gos/internal/config" "codeberg.org/snonux/gos/internal/entry" "codeberg.org/snonux/gos/internal/platforms/linkedin/oauth2" @@ -27,7 +27,7 @@ const ( func Post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) error { err := post(ctx, args, sizeLimit, en) if errors.Is(err, errUnauthorized) { - log.Println(err, "=> trying to refresh LinkedIn access token") + colour.Infoln(err, "=> trying to refresh LinkedIn access token") args.Secrets.LinkedInAccessToken = "" // Reset the token return post(ctx, args, sizeLimit, en) } @@ -36,7 +36,7 @@ func Post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) func post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) error { if args.DryRun { - log.Println("Not posting", en, "to LinkedIn as dry-run enabled") + colour.Infoln("Not posting", en, "to LinkedIn as dry-run enabled") return nil } @@ -63,7 +63,7 @@ func post(ctx context.Context, args config.Args, sizeLimit int, en entry.Entry) if filePath, err = prev.DownloadImage(args.CacheDir); err != nil { return err } - log.Println("Downloaded preview image to ", filePath) + colour.Infoln("Downloaded preview image to ", filePath) } question := fmt.Sprintf("Do you want to post this message to Linkedin (%v)?", prev) diff --git a/internal/platforms/linkedin/oauth2/oauth2.go b/internal/platforms/linkedin/oauth2/oauth2.go index 9a6c84d..51beec9 100644 --- a/internal/platforms/linkedin/oauth2/oauth2.go +++ b/internal/platforms/linkedin/oauth2/oauth2.go @@ -6,12 +6,12 @@ import ( "errors" "fmt" "io" - "log" "net/http" "os/exec" "runtime" "time" + "codeberg.org/snonux/gos/internal/colour" "codeberg.org/snonux/gos/internal/config" "golang.org/x/oauth2" "golang.org/x/oauth2/linkedin" @@ -72,7 +72,7 @@ func oauthCallbackHandler(w http.ResponseWriter, r *http.Request) { defer close(errCh) code := r.URL.Query().Get("code") - log.Println("Exchanging OAuth2 token") + colour.Infoln("Exchanging OAuth2 token") token, err := oauthConfig.Exchange(globalCtx, code) if err != nil { _, _ = w.Write([]byte(err.Error())) @@ -110,7 +110,7 @@ func LinkedInCreds(ctx context.Context, args config.Args) (string, string, error http.HandleFunc("/callback", oauthCallbackHandler) http.HandleFunc("/up", upHandler) - log.Println("Listening on http://localhost:8080 for LinkedIn OAuth2") + colour.Infoln("Listening on http://localhost:8080 for LinkedIn OAuth2") go func() { if err := http.ListenAndServe(":8080", nil); err != nil { errCh <- err @@ -139,7 +139,7 @@ func LinkedInCreds(ctx context.Context, args config.Args) (string, string, error } func openURLInFirefox(browser, url string) error { - log.Println("Opening", url, "in", browser) + colour.Infoln("Opening", url, "in", browser) switch runtime.GOOS { case "windows": cmd := exec.Command("cmd", "/C", "start", browser, url) @@ -162,9 +162,11 @@ func WaitUntilURLIsReachable(url string) error { resp, err := http.Get(url) if err != nil { - log.Printf("URL is not reachable: %v\n", err) + colour.Infof("URL is not reachable: %v", err) + fmt.Print("\n") } else { - log.Printf("URL is reachable: %s - Status Code: %d\n", url, resp.StatusCode) + colour.Infof("URL is reachable: %s - Status Code: %d", url, resp.StatusCode) + fmt.Print("\n") resp.Body.Close() return nil } diff --git a/internal/platforms/linkedin/preview.go b/internal/platforms/linkedin/preview.go index 2e40798..6a16536 100644 --- a/internal/platforms/linkedin/preview.go +++ b/internal/platforms/linkedin/preview.go @@ -5,12 +5,12 @@ import ( "errors" "fmt" "io" - "log" "net/http" "net/url" "os" "path/filepath" + "codeberg.org/snonux/gos/internal/colour" "codeberg.org/snonux/gos/internal/oi" "golang.org/x/net/html" ) @@ -30,11 +30,11 @@ func NewPreview(ctx context.Context, urls []string) (preview, error) { } title, imageURL, err := extractFromURL(ctx, urls[0]) if errors.Is(err, errNoTitleElementFound) || title == "" { - log.Println("Setting title to", urls[0]) + colour.Infoln("Setting title to", urls[0]) title = urls[0] } if errors.Is(err, errNoImageElementFound) { - log.Println("URL", urls[0], "without any image, that's fine, though.") + colour.Infoln("URL", urls[0], "without any image, that's fine, though.") err = nil } return preview{title: title, imageURL: imageURL, url: urls[0]}, err |
