Updated MAL sync

This commit is contained in:
2018-11-01 08:23:41 +09:00
parent 3ccf470cf0
commit 9d57aaf12a
5 changed files with 169 additions and 124 deletions

View File

@ -26,28 +26,32 @@ func main() {
return
}
// Sync the most important ones first
allAnime := arn.FilterAnime(func(anime *arn.Anime) bool {
return anime.GetMapping("myanimelist/anime") != ""
})
// Sync anime
if objectType == "all" || objectType == "anime" {
allAnime := arn.FilterAnime(func(anime *arn.Anime) bool {
return anime.GetMapping("myanimelist/anime") != ""
})
arn.SortAnimeByQuality(allAnime)
color.Yellow("%d anime found", len(allAnime))
arn.SortAnimeByQuality(allAnime)
color.Yellow("%d anime found", len(allAnime))
for _, anime := range allAnime {
syncAnime(anime, anime.GetMapping("myanimelist/anime"))
for _, anime := range allAnime {
syncAnime(anime, anime.GetMapping("myanimelist/anime"))
}
}
// Sync the most important ones first
allCharacters := arn.FilterCharacters(func(character *arn.Character) bool {
return character.GetMapping("myanimelist/character") != ""
})
// Sync characters
if objectType == "all" || objectType == "character" {
allCharacters := arn.FilterCharacters(func(character *arn.Character) bool {
return character.GetMapping("myanimelist/character") != ""
})
arn.SortCharactersByLikes(allCharacters)
color.Yellow("%d characters found", len(allCharacters))
arn.SortCharactersByLikes(allCharacters)
color.Yellow("%d characters found", len(allCharacters))
for _, character := range allCharacters {
syncCharacter(character, character.GetMapping("myanimelist/character"))
for _, character := range allCharacters {
syncCharacter(character, character.GetMapping("myanimelist/character"))
}
}
}
@ -99,6 +103,13 @@ func syncCharacter(character *arn.Character, malID string) {
description, attributes := parseCharacterDescription(malCharacter.Description)
character.Description = description
character.Attributes = attributes
character.Spoilers = []arn.Spoiler{}
for _, spoilerText := range malCharacter.Spoilers {
character.Spoilers = append(character.Spoilers, arn.Spoiler{
Text: spoilerText,
})
}
if character.Name.Japanese == "" && malCharacter.JapaneseName != "" {
character.Name.Japanese = malCharacter.JapaneseName

View File

@ -7,28 +7,41 @@ import (
)
// Shell parameters
var animeID string
var objectType string
var objectID string
// Shell flags
func init() {
flag.StringVar(&animeID, "id", "", "ID of the notify.moe anime you want to refresh")
flag.StringVar(&objectType, "type", "all", "all | anime | character")
flag.StringVar(&objectID, "id", "", "ID of the notify.moe anime/character you want to refresh")
flag.Parse()
}
// InvokeShellArgs ...
func InvokeShellArgs() bool {
if animeID != "" {
anime, err := arn.GetAnime(animeID)
if objectID != "" {
switch objectType {
case "anime":
anime, err := arn.GetAnime(objectID)
arn.PanicOnError(err)
if err != nil {
panic(err)
if anime.GetMapping("myanimelist/anime") == "" {
panic("No MAL ID")
}
syncAnime(anime, anime.GetMapping("myanimelist/anime"))
case "character":
character, err := arn.GetCharacter(objectID)
arn.PanicOnError(err)
if character.GetMapping("myanimelist/character") == "" {
panic("No MAL ID")
}
syncCharacter(character, character.GetMapping("myanimelist/character"))
}
if anime.GetMapping("myanimelist/anime") == "" {
panic("No MAL ID")
}
syncAnime(anime, anime.GetMapping("myanimelist/anime"))
return true
}