From 0baf37f1bf6ca7af5aa9882d280de567e9be7b8f Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 9 Nov 2018 07:54:02 +0900 Subject: [PATCH] Updated MAL sync --- jobs/mal-sync/mal-sync.go | 45 +++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/jobs/mal-sync/mal-sync.go b/jobs/mal-sync/mal-sync.go index 28979fdf..0784ac4a 100644 --- a/jobs/mal-sync/mal-sync.go +++ b/jobs/mal-sync/mal-sync.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strings" "github.com/animenotifier/arn" "github.com/animenotifier/mal" @@ -93,28 +94,40 @@ func syncCharacter(character *arn.Character, malID string) { return } - // Skip manually created characters - if character.CreatedBy != "" { - return - } - malCharacter := obj.(*mal.Character) - 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 } + // Unless it's a manually created or edited character, + // update the description. + if character.CreatedBy == "" && character.EditedBy == "" { + description, attributes := parseCharacterDescription(malCharacter.Description) + character.Name.Canonical = malCharacter.Name + character.Description = description + character.Attributes = attributes + character.Spoilers = []arn.Spoiler{} + + for _, spoilerText := range malCharacter.Spoilers { + if !strings.Contains(strings.TrimSpace(spoilerText), "\n\n") { + character.Spoilers = append(character.Spoilers, arn.Spoiler{ + Text: spoilerText, + }) + + continue + } + + paragraphs := strings.Split(spoilerText, "\n\n") + + for _, paragraph := range paragraphs { + character.Spoilers = append(character.Spoilers, arn.Spoiler{ + Text: paragraph, + }) + } + } + } + // Save in database character.Save() }