Added basic MAL character import
This commit is contained in:
parent
b59da5f617
commit
234945cd79
@ -8,6 +8,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/animenotifier/mal"
|
||||||
|
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
"github.com/animenotifier/mal/parser"
|
"github.com/animenotifier/mal/parser"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
@ -48,7 +50,7 @@ func readFile(name string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
anime, err := malparser.ParseAnime(file)
|
anime, characters, err := malparser.ParseAnime(file)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@ -59,6 +61,36 @@ func readFile(name string) error {
|
|||||||
return errors.New("Empty ID")
|
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)
|
// fmt.Println(anime.ID, anime.Title)
|
||||||
arn.MAL.Set("Anime", anime.ID, anime)
|
arn.MAL.Set("Anime", anime.ID, anime)
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user