code styling improvements
This commit is contained in:
parent
8c1f642e33
commit
3d71a16633
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
|
"errors"
|
||||||
"gopher-toolbox/config"
|
"gopher-toolbox/config"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -45,11 +46,11 @@ func migrateDB() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = m.Up()
|
err = m.Up()
|
||||||
if err != nil && err != migrate.ErrNoChange {
|
if err != nil && !errors.Is(err, migrate.ErrNoChange) {
|
||||||
slog.Error("cannot migrate", "error", err)
|
slog.Error("cannot migrate", "error", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if err == migrate.ErrNoChange {
|
if errors.Is(err, migrate.ErrNoChange) {
|
||||||
slog.Info("migration has no changes")
|
slog.Info("migration has no changes")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,5 +33,5 @@ select avg(avg_rating) from "episodes"
|
|||||||
where tv_show_id = $1 and season = $2;
|
where tv_show_id = $1 and season = $2;
|
||||||
|
|
||||||
-- name: SeasonMedianRating :one
|
-- name: SeasonMedianRating :one
|
||||||
-- select percentile_cont(0.5) within group (order by avg_rating) from "episodes"
|
select percentile_cont(0.5) within group (order by avg_rating) from "episodes"
|
||||||
-- where tv_show_id = $1 and season = $2;
|
where tv_show_id = $1 and season = $2;
|
||||||
@ -28,7 +28,7 @@ type Episode struct {
|
|||||||
func (e Episode) ToEpisodeParams(tvShowID int32) sqlc.CreateEpisodesParams {
|
func (e Episode) ToEpisodeParams(tvShowID int32) sqlc.CreateEpisodesParams {
|
||||||
|
|
||||||
var date pgtype.Date
|
var date pgtype.Date
|
||||||
date.Scan(e.Released)
|
_ = date.Scan(e.Released)
|
||||||
|
|
||||||
return sqlc.CreateEpisodesParams{
|
return sqlc.CreateEpisodesParams{
|
||||||
TvShowID: tvShowID,
|
TvShowID: tvShowID,
|
||||||
@ -82,7 +82,7 @@ func ScrapeEpisodes(ttImdb string) (string, []Episode) {
|
|||||||
|
|
||||||
c.OnScraped(func(r *colly.Response) {
|
c.OnScraped(func(r *colly.Response) {
|
||||||
seasonMap := make(map[int]bool)
|
seasonMap := make(map[int]bool)
|
||||||
uniqueSeasons := []int{}
|
var uniqueSeasons []int
|
||||||
slog.Info("scraped seasons", "seasons", seasons)
|
slog.Info("scraped seasons", "seasons", seasons)
|
||||||
for _, seasonNum := range seasons {
|
for _, seasonNum := range seasons {
|
||||||
if !seasonMap[seasonNum] {
|
if !seasonMap[seasonNum] {
|
||||||
@ -103,13 +103,13 @@ func ScrapeEpisodes(ttImdb string) (string, []Episode) {
|
|||||||
for _, seasonNum := range uniqueSeasons {
|
for _, seasonNum := range uniqueSeasons {
|
||||||
seasonURL := fmt.Sprintf(imdbEpisodesURL, ttImdb, seasonNum)
|
seasonURL := fmt.Sprintf(imdbEpisodesURL, ttImdb, seasonNum)
|
||||||
slog.Info("visiting season", "url", seasonURL)
|
slog.Info("visiting season", "url", seasonURL)
|
||||||
episodeCollector.Visit(seasonURL)
|
_ = episodeCollector.Visit(seasonURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
episodeCollector.Wait()
|
episodeCollector.Wait()
|
||||||
})
|
})
|
||||||
|
|
||||||
c.Visit(fmt.Sprintf(visitURL, ttImdb))
|
_ = c.Visit(fmt.Sprintf(visitURL, ttImdb))
|
||||||
c.Wait()
|
c.Wait()
|
||||||
|
|
||||||
slog.Info("scraped all seasons", "length", len(allSeasons))
|
slog.Info("scraped all seasons", "length", len(allSeasons))
|
||||||
|
|||||||
@ -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)
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user