Implemented basic importer
This commit is contained in:
parent
84ac0583d1
commit
0ec3de0477
85
jobs/import-jikan-characters/import-jikan-characters.go
Normal file
85
jobs/import-jikan-characters/import-jikan-characters.go
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/animenotifier/jikan"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
)
|
||||||
|
|
||||||
|
var jikanDB = arn.Node.Namespace("jikan")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
color.Yellow("Importing jikan characters...")
|
||||||
|
defer arn.Node.Close()
|
||||||
|
|
||||||
|
for characterObj := range jikanDB.All("Character") {
|
||||||
|
jikanCharacter := characterObj.(*jikan.Character)
|
||||||
|
|
||||||
|
if jikanCharacter.Name != "Slaine Troyard" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
character := &arn.Character{
|
||||||
|
ID: arn.GenerateID("Character"),
|
||||||
|
Description: jikanCharacter.About,
|
||||||
|
Name: &arn.CharacterName{
|
||||||
|
Romaji: jikanCharacter.Name,
|
||||||
|
Japanese: jikanCharacter.NameJapanese,
|
||||||
|
},
|
||||||
|
Image: jikanCharacter.Image,
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(character.Name.Japanese, "(") {
|
||||||
|
character.Name.Japanese = strings.TrimPrefix(character.Name.Japanese, "(")
|
||||||
|
character.Name.Japanese = strings.TrimSuffix(character.Name.Japanese, ")")
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := strings.Split(character.Description, "\n")
|
||||||
|
finalLines := make([]string, 0, len(lines))
|
||||||
|
|
||||||
|
for _, line := range lines {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
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 < 2 || colonPos > 25 {
|
||||||
|
finalLines = append(finalLines, originalLine)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
key := line[:colonPos]
|
||||||
|
value := line[colonPos+1:]
|
||||||
|
|
||||||
|
value = strings.TrimSpace(value)
|
||||||
|
|
||||||
|
if key == "source" {
|
||||||
|
key = "Source"
|
||||||
|
}
|
||||||
|
|
||||||
|
character.Attributes = append(character.Attributes, &arn.CharacterAttribute{
|
||||||
|
Name: key,
|
||||||
|
Value: value,
|
||||||
|
})
|
||||||
|
|
||||||
|
fmt.Println(color.CyanString(key), color.YellowString(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
character.Description = strings.Join(finalLines, "\n")
|
||||||
|
character.Description = strings.TrimSpace(character.Description)
|
||||||
|
|
||||||
|
arn.PrettyPrint(character)
|
||||||
|
}
|
||||||
|
|
||||||
|
color.Green("Finished.")
|
||||||
|
}
|
@ -48,5 +48,5 @@ func sync(anime *arn.Anime, malID string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Error fetching %s: %v", malID, err)
|
fmt.Printf("Error fetching %s: %v\n", malID, err)
|
||||||
}
|
}
|
||||||
|
@ -59,5 +59,5 @@ func fetchCharacter(malCharacterID string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Error fetching %s: %v", malCharacterID, err)
|
fmt.Printf("Error fetching %s: %v\n", malCharacterID, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user