From 3d1891e1a744d96ce62c7e5446886097a52136ff Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 29 Nov 2017 06:48:58 +0100 Subject: [PATCH] Cleanup --- .../import-mal-companies.go} | 0 .../import-mal-files.go} | 0 .../import-mal-genres/import-mal-genres.go | 40 +++++++++++++++++++ 3 files changed, 40 insertions(+) rename patches/{import-companies/import-companies.go => import-mal-companies/import-mal-companies.go} (100%) rename patches/{import-mal-db/import-mal-db.go => import-mal-files/import-mal-files.go} (100%) create mode 100644 patches/import-mal-genres/import-mal-genres.go diff --git a/patches/import-companies/import-companies.go b/patches/import-mal-companies/import-mal-companies.go similarity index 100% rename from patches/import-companies/import-companies.go rename to patches/import-mal-companies/import-mal-companies.go diff --git a/patches/import-mal-db/import-mal-db.go b/patches/import-mal-files/import-mal-files.go similarity index 100% rename from patches/import-mal-db/import-mal-db.go rename to patches/import-mal-files/import-mal-files.go diff --git a/patches/import-mal-genres/import-mal-genres.go b/patches/import-mal-genres/import-mal-genres.go new file mode 100644 index 00000000..c83f184b --- /dev/null +++ b/patches/import-mal-genres/import-mal-genres.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + + "github.com/animenotifier/arn" + "github.com/animenotifier/mal" + "github.com/fatih/color" +) + +var malDB = arn.Node.Namespace("mal").RegisterTypes((*mal.Anime)(nil)) + +func main() { + defer arn.Node.Close() + color.Yellow("Importing genres") + + for anime := range arn.StreamAnime() { + malID := anime.GetMapping("myanimelist/anime") + + if malID == "" { + continue + } + + sync(anime, malID) + } + + color.Green("Finished importing genres") +} + +func sync(anime *arn.Anime, malID string) { + obj, err := malDB.Get("Anime", malID) + + if err != nil { + fmt.Println(err) + return + } + + malAnime := obj.(*mal.Anime) + anime.Genres = malAnime.Genres +}