From 3d71a166332ba0d33796c6d36656f6008aeca1f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20P=C3=A9rez?= Date: Wed, 6 Nov 2024 22:18:54 +0100 Subject: [PATCH] code styling improvements --- core/cmd/main.go | 5 +++-- core/database/queries/tv_show.sql | 4 ++-- core/internal/scraper/tvshow.go | 8 ++++---- core/utils/times.go | 28 ---------------------------- 4 files changed, 9 insertions(+), 36 deletions(-) delete mode 100644 core/utils/times.go diff --git a/core/cmd/main.go b/core/cmd/main.go index d486845..d601a26 100644 --- a/core/cmd/main.go +++ b/core/cmd/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/gob" + "errors" "gopher-toolbox/config" "log/slog" "net/http" @@ -45,11 +46,11 @@ func migrateDB() { } err = m.Up() - if err != nil && err != migrate.ErrNoChange { + if err != nil && !errors.Is(err, migrate.ErrNoChange) { slog.Error("cannot migrate", "error", err) panic(err) } - if err == migrate.ErrNoChange { + if errors.Is(err, migrate.ErrNoChange) { slog.Info("migration has no changes") } diff --git a/core/database/queries/tv_show.sql b/core/database/queries/tv_show.sql index 6090617..3fb917b 100644 --- a/core/database/queries/tv_show.sql +++ b/core/database/queries/tv_show.sql @@ -33,5 +33,5 @@ select avg(avg_rating) from "episodes" where tv_show_id = $1 and season = $2; -- name: SeasonMedianRating :one --- select percentile_cont(0.5) within group (order by avg_rating) from "episodes" --- where tv_show_id = $1 and season = $2; \ No newline at end of file +select percentile_cont(0.5) within group (order by avg_rating) from "episodes" +where tv_show_id = $1 and season = $2; \ No newline at end of file diff --git a/core/internal/scraper/tvshow.go b/core/internal/scraper/tvshow.go index 9b69242..ffe63e8 100644 --- a/core/internal/scraper/tvshow.go +++ b/core/internal/scraper/tvshow.go @@ -28,7 +28,7 @@ type Episode struct { func (e Episode) ToEpisodeParams(tvShowID int32) sqlc.CreateEpisodesParams { var date pgtype.Date - date.Scan(e.Released) + _ = date.Scan(e.Released) return sqlc.CreateEpisodesParams{ TvShowID: tvShowID, @@ -82,7 +82,7 @@ func ScrapeEpisodes(ttImdb string) (string, []Episode) { c.OnScraped(func(r *colly.Response) { seasonMap := make(map[int]bool) - uniqueSeasons := []int{} + var uniqueSeasons []int slog.Info("scraped seasons", "seasons", seasons) for _, seasonNum := range seasons { if !seasonMap[seasonNum] { @@ -103,13 +103,13 @@ func ScrapeEpisodes(ttImdb string) (string, []Episode) { for _, seasonNum := range uniqueSeasons { seasonURL := fmt.Sprintf(imdbEpisodesURL, ttImdb, seasonNum) slog.Info("visiting season", "url", seasonURL) - episodeCollector.Visit(seasonURL) + _ = episodeCollector.Visit(seasonURL) } episodeCollector.Wait() }) - c.Visit(fmt.Sprintf(visitURL, ttImdb)) + _ = c.Visit(fmt.Sprintf(visitURL, ttImdb)) c.Wait() slog.Info("scraped all seasons", "length", len(allSeasons)) diff --git a/core/utils/times.go b/core/utils/times.go deleted file mode 100644 index 2370e07..0000000 --- a/core/utils/times.go +++ /dev/null @@ -1,28 +0,0 @@ -package utils - -import "time" - -// TODO: Move to toolbox -func TimeParser(timeString string) (time.Time, error) { - if len(timeString) == 1 { - return time.Time{}, nil - } - if len(timeString) == 4 { - return time.Parse("2006", timeString) - } - if len(timeString) == 9 { - return time.Parse("Jan. 2006", timeString) - } - if len(timeString) == 10 { - return time.Parse("2 Jan 2006", timeString) - } - if len(timeString) == 11 { - if timeString[5:6] == "." { - return time.Parse("2 Jan. 2006", timeString) - } else { - return time.Parse("2 Jan 2006", timeString) - } - } - - return time.Parse("2 Jan. 2006", timeString) -}