From 112bec862eabec10a6814689073d8da627dbf6f0 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 11 Jul 2017 13:26:53 +0200 Subject: [PATCH] Improved twist.moe updater --- jobs/twist/twist.go | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/jobs/twist/twist.go b/jobs/twist/twist.go index 88b14325..0182a389 100644 --- a/jobs/twist/twist.go +++ b/jobs/twist/twist.go @@ -3,7 +3,6 @@ package main import ( "fmt" "os" - "strings" "time" "github.com/animenotifier/arn" @@ -22,9 +21,6 @@ func main() { color.Yellow("Refreshing twist.moe links for %d anime", len(idList)) for count, animeID := range idList { - // Wait for rate limiter - <-rateLimiter.C - anime, animeErr := arn.GetAnime(animeID) if animeErr != nil { @@ -35,37 +31,13 @@ func main() { // Log fmt.Fprintf(os.Stdout, "[%d / %d] ", count+1, len(idList)) - // Get twist.moe feed - feed, err := twist.GetFeedByKitsuID(animeID) + // Refresh + anime.RefreshEpisodes() - if err != nil { - color.Red("Error querying ID %s: %v", animeID, err) - continue - } + // Ok + color.Green("Found %d episodes for anime %s", len(anime.Episodes().Items), animeID) - episodes := feed.Episodes - - // // Sort by episode number - // sort.Slice(episodes, func(a, b int) bool { - // return episodes[a].Number < episodes[b].Number - // }) - - for _, episode := range episodes { - arnEpisode := anime.EpisodeByNumber(episode.Number) - - if arnEpisode == nil { - color.Red("Anime %s Episode %d not found", anime.ID, episode.Number) - continue - } - - if arnEpisode.Links == nil { - arnEpisode.Links = map[string]string{} - } - - arnEpisode.Links["twist.moe"] = strings.Replace(episode.Link, "https://test.twist.moe/", "https://twist.moe/", 1) - } - - arn.PanicOnError(anime.Episodes().Save()) - color.Green("Found %d episodes for anime %s", len(episodes), animeID) + // Wait for rate limiter + <-rateLimiter.C } }