Added basic MAL character import

This commit is contained in:
Eduard Urbach 2018-04-12 11:05:55 +02:00
parent b59da5f617
commit 234945cd79

View File

@ -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