Skip to content

Commit

Permalink
time fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lieranderl committed Dec 14, 2024
1 parent d36ea80 commit d8cdbc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
19 changes: 10 additions & 9 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package main

import (
"context"
"fmt"
"strings"
// "fmt"
"log"

"os"
Expand All @@ -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()
Expand All @@ -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() {
Expand Down
11 changes: 6 additions & 5 deletions internal/trackers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions internal/trackers/rutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d8cdbc7

Please sign in to comment.