From 3a6cd6b3bc3a0b8bbd1580e7ae6b9e981028179b Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 30 Oct 2018 12:01:42 +0900 Subject: [PATCH] Updated MAL tools --- jobs/mal-parse/mal-parse.go | 41 +++++++++++++++++++++++++++++++++---- jobs/mal-parse/shell.go | 2 +- jobs/mal-sync/sync.go | 4 ++-- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/jobs/mal-parse/mal-parse.go b/jobs/mal-parse/mal-parse.go index 3df92f9d..6028e11a 100644 --- a/jobs/mal-parse/mal-parse.go +++ b/jobs/mal-parse/mal-parse.go @@ -41,11 +41,11 @@ func main() { return nil } - return readFile(name) + return readAnimeFile(name) }) } -func readFile(name string) error { +func readAnimeFile(name string) error { file, err := os.Open(name) if err != nil { @@ -89,8 +89,8 @@ func readFile(name string) error { modified = true } - if existing.ImagePath != character.ImagePath { - existing.ImagePath = character.ImagePath + if existing.Image != character.Image { + existing.Image = character.Image modified = true } @@ -103,3 +103,36 @@ func readFile(name string) error { arn.MAL.Set("Anime", anime.ID, anime) return nil } + +func readCharacterFile(name string) error { + file, err := os.Open(name) + + if err != nil { + fmt.Println(err) + return err + } + + defer file.Close() + + reader, err := gzip.NewReader(file) + + if err != nil { + fmt.Println(err) + return err + } + + character, err := malparser.ParseCharacter(reader) + + if err != nil { + fmt.Println(err) + return err + } + + if character.ID == "" { + return errors.New("Empty ID") + } + + fmt.Println(character.ID, character.Name) + arn.MAL.Set("Character", character.ID, character) + return nil +} diff --git a/jobs/mal-parse/shell.go b/jobs/mal-parse/shell.go index 1862f8dd..3a50c91e 100644 --- a/jobs/mal-parse/shell.go +++ b/jobs/mal-parse/shell.go @@ -29,7 +29,7 @@ func InvokeShellArgs() bool { panic("No MAL ID") } - readFile(path.Join(arn.Root, "jobs/mal-download/anime", "anime-"+anime.GetMapping("myanimelist/anime")+".html")) + readAnimeFile(path.Join(arn.Root, "jobs/mal-download/anime", "anime-"+anime.GetMapping("myanimelist/anime")+".html")) return true } diff --git a/jobs/mal-sync/sync.go b/jobs/mal-sync/sync.go index 225d06a2..b47d4bf3 100644 --- a/jobs/mal-sync/sync.go +++ b/jobs/mal-sync/sync.go @@ -106,7 +106,7 @@ func syncCharacters(anime *arn.Anime, malAnime *mal.Anime) { malCharacter := obj.(*mal.Character) - if malCharacter.ID == "" || malCharacter.Name == "" || malCharacter.ImagePath == "" { + if malCharacter.ID == "" || malCharacter.Name == "" || malCharacter.Image == "" { fmt.Println("Skip character:", malAnimeCharacter.ID) continue } @@ -159,7 +159,7 @@ func syncCharacters(anime *arn.Anime, malAnime *mal.Anime) { // import character func importCharacter(malCharacter *mal.Character) *arn.Character { - fmt.Println("Importing MAL Character:", malCharacter.ID, malCharacter.Name, malCharacter.ImagePath) + fmt.Println("Importing MAL Character:", malCharacter.ID, malCharacter.Name, malCharacter.Image) character := arn.NewCharacter() character.Name.Canonical = malCharacter.Name