From d8cdbc7ec0e47dde6bf1960fbafb47497359a6d3 Mon Sep 17 00:00:00 2001 From: lieranderl <19622412+lieranderl@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:21:15 +0100 Subject: [PATCH] time fix --- cmd/main.go | 19 ++++++++++--------- internal/trackers/common.go | 11 ++++++----- internal/trackers/rutor.go | 1 + 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 852eef4..6e20d5f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -3,7 +3,8 @@ package main import ( "context" - "fmt" + "strings" + // "fmt" "log" "os" @@ -19,18 +20,18 @@ func main() { start := time.Now() godotenv.Load() - urls := []string{fmt.Sprintf(os.Getenv("KZ_SEARCH_URL"), "Bad boys", "2024"), fmt.Sprintf(os.Getenv("RUTOR_SEARCH_URL"), "Bad boys", "2024")} + // urls := []string{fmt.Sprintf(os.Getenv("KZ_SEARCH_URL"), "Bad boys", "2024"), fmt.Sprintf(os.Getenv("RUTOR_SEARCH_URL"), "Bad boys", "2024")} - // rutorUrls := strings.Split(os.Getenv("RUTOR_DV_URLS"), ",") - // kinizalUrls := strings.Split(os.Getenv("KINOZAL_DV_URLS"), ",") - // urls := append(rutorUrls, kinizalUrls...) + rutorUrls := strings.Split(os.Getenv("RUTOR_DV_URLS"), ",") + kinizalUrls := strings.Split(os.Getenv("KINOZAL_DV_URLS"), ",") + urls := append(rutorUrls, kinizalUrls...) // Initialize the pipeline pipeline := executor.InitPipeline(context.Background(), urls, os.Getenv("TMDBAPIKEY"), executor.OptionWithMongo(os.Getenv("MONGO_URI"))) err := pipeline. RunTrackersSearchPipeline(true). - // ConvertTorrentsToMovieShort(). + ConvertTorrentsToMovieShort(). // Tmdb(). // SaveToDb(). HandleErrors() @@ -40,9 +41,9 @@ func main() { log.Println(pipeline) // pring all collected movies - // for _, m := range pipeline.GetMovies() { - // log.Println("Movie:", m.ID, m.Title, m.OriginalTitle, m.Year, m.VoteAverage) - // } + for _, m := range pipeline.GetMovies() { + log.Println("Movie:", m.ID, m.Title, m.OriginalTitle, m.Year, m.VoteAverage) + } // print all torrents for _, torrent := range pipeline.GetTorrents() { diff --git a/internal/trackers/common.go b/internal/trackers/common.go index e76af6d..f9592e8 100644 --- a/internal/trackers/common.go +++ b/internal/trackers/common.go @@ -69,13 +69,14 @@ func ParseDate(dateStr string, format string) (string, error) { timeNow := time.Now() switch { case strings.Contains(dateStr, "сегодня"): - return monday.Format(timeNow, layout, monday.LocaleRuRU), nil + // timeNow to 2006-01-02 format + return timeNow.Format(layout), nil case strings.Contains(dateStr, "вчера"): - return monday.Format(timeNow.AddDate(0, 0, -1), layout, monday.LocaleRuRU), nil + return timeNow.AddDate(0, 0, -1).Format(layout), nil default: - // Try parsing with the provided format - if parsedTime, err := monday.Parse(format, dateStr, monday.LocaleRuRU); err == nil { - return monday.Format(parsedTime, layout, monday.LocaleRuRU), nil + cleanDateStr := strings.ReplaceAll(dateStr, "\u00A0", " ") + if parsedTime, err := monday.Parse(format, cleanDateStr, monday.LocaleRuRU); err == nil { + return parsedTime.Format(layout), nil } return "", fmt.Errorf("failed to parse date: %s", dateStr) } diff --git a/internal/trackers/rutor.go b/internal/trackers/rutor.go index 0ce4847..02ece46 100644 --- a/internal/trackers/rutor.go +++ b/internal/trackers/rutor.go @@ -77,6 +77,7 @@ func (p *RutorParser) parseTorrentElement(e *colly.HTMLElement) *torrents.Torren torrent.Year = title.Year // Parse date + if date, err := ParseDate(listst[0], p.config.ParseConfig.DateFormat); err == nil { torrent.Date = date }