Updated MAL tools

This commit is contained in:
Eduard Urbach 2018-10-30 12:01:42 +09:00
parent 85cd5538b6
commit 3a6cd6b3bc
3 changed files with 40 additions and 7 deletions

View File

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

View File

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

View File

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