From e3997a8f497a888ffa4e79489d631cfa65952abc Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 10 Mar 2018 22:21:31 +0100 Subject: [PATCH] Added patch to add genres --- patches/add-mal-genres/add-mal-genres.go | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 patches/add-mal-genres/add-mal-genres.go diff --git a/patches/add-mal-genres/add-mal-genres.go b/patches/add-mal-genres/add-mal-genres.go new file mode 100644 index 00000000..1463b616 --- /dev/null +++ b/patches/add-mal-genres/add-mal-genres.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + + "github.com/animenotifier/arn" + "github.com/animenotifier/mal" + "github.com/fatih/color" +) + +func main() { + defer arn.Node.Close() + + count := 0 + + for anime := range arn.StreamAnime() { + if len(anime.Genres) > 0 { + continue + } + + malID := anime.GetMapping("myanimelist/anime") + + if malID == "" { + continue + } + + malAnimeObj, err := arn.MAL.Get("Anime", malID) + + if err != nil { + continue + } + + malAnime := malAnimeObj.(*mal.Anime) + + if len(malAnime.Genres) == 0 { + continue + } + + anime.Genres = malAnime.Genres + anime.Save() + + count++ + + fmt.Println(anime.ID, anime, anime.Genres) + } + + color.Green("Added genres to %d anime", count) +}