diff --git a/jobs/sync-characters/sync-characters.go b/jobs/sync-characters/sync-characters.go index de487b3d..8d4165e0 100644 --- a/jobs/sync-characters/sync-characters.go +++ b/jobs/sync-characters/sync-characters.go @@ -25,6 +25,45 @@ func main() { // We use markdown, so replace
with two line breaks. character.Description = strings.Replace(character.Description, "
", "\n\n", -1) + + // Parse attributes like these: + // - Position: Club Manager + // - Height: 162 cm (5' 4") + // - Weight: 48 kg (106 lb) + // - Birthday: November 24 + // - Hair color: Brown + // - Eyes: Blue (anime), Green (manga) + + lines := strings.Split(character.Description, "\n\n") + finalLines := make([]string, 0, len(lines)) + + for _, line := range lines { + originalLine := line + + if strings.HasPrefix(line, "(") { + line = strings.TrimPrefix(line, "(") + line = strings.TrimSuffix(line, ")") + } + + line = strings.TrimSpace(line) + + colonPos := strings.Index(line, ":") + + if colonPos == -1 || colonPos > 25 { + finalLines = append(finalLines, originalLine) + continue + } + + key := line[:colonPos] + value := line[colonPos+1:] + + value = strings.TrimSpace(value) + + fmt.Println(color.CyanString(key), color.YellowString(value)) + } + + character.Description = strings.Join(finalLines, "\n\n") + character.Description = strings.Trim(character.Description, "\n\n") character.Save() fmt.Printf("%s %s %s\n", color.GreenString("✔"), character.ID, character.Name)