diff --git a/jobs/mal-import/mal-import.go b/jobs/mal-import/mal-import.go index 01266b9a..e5cc85f8 100644 --- a/jobs/mal-import/mal-import.go +++ b/jobs/mal-import/mal-import.go @@ -8,6 +8,8 @@ import ( "path/filepath" "strings" + "github.com/animenotifier/mal" + "github.com/animenotifier/arn" "github.com/animenotifier/mal/parser" "github.com/fatih/color" @@ -48,7 +50,7 @@ func readFile(name string) error { return err } - anime, err := malparser.ParseAnime(file) + anime, characters, err := malparser.ParseAnime(file) if err != nil { fmt.Println(err) @@ -59,6 +61,36 @@ func readFile(name string) error { return errors.New("Empty ID") } + for _, character := range characters { + obj, err := arn.MAL.Get("Character", character.ID) + + if err != nil { + arn.MAL.Set("Character", character.ID, character) + continue + } + + existing := obj.(*mal.Character) + modified := false + + if existing.Name != character.Name { + existing.Name = character.Name + modified = true + } + + if existing.ImagePath != character.ImagePath { + existing.ImagePath = character.ImagePath + modified = true + } + + if modified { + arn.MAL.Set("Character", existing.ID, existing) + } + } + + for _, character := range anime.Characters { + fmt.Println(character) + } + // fmt.Println(anime.ID, anime.Title) arn.MAL.Set("Anime", anime.ID, anime) return nil