You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.3 KiB
62 lines
1.3 KiB
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
|
|
"git.aiterp.net/rpdata/api/internal/store"
|
|
"git.aiterp.net/rpdata/api/model/character"
|
|
)
|
|
|
|
var fileName = flag.String("file", "./characters.json", "json file to load")
|
|
|
|
func main() {
|
|
file, err := os.Open(*fileName)
|
|
if err != nil {
|
|
log.Fatalln("Open:", err)
|
|
}
|
|
|
|
infos, err := load(file)
|
|
if err != nil {
|
|
log.Fatalln("Parse:", err)
|
|
}
|
|
|
|
err = store.Init()
|
|
if err != nil {
|
|
log.Fatalln("Store:", err)
|
|
}
|
|
|
|
charsAdded, charsFailed := 0, 0
|
|
nicksAdded, nicksFailed := 0, 0
|
|
|
|
for _, info := range infos {
|
|
char, err := character.New(info.Nicks[0], info.Name, info.ShortName, info.Author, "")
|
|
if err != nil {
|
|
log.Println(info.Nicks[0], "failed to insert:", err)
|
|
charsFailed++
|
|
|
|
char, err = character.FindNick(info.Nicks[0])
|
|
if err != nil {
|
|
continue
|
|
}
|
|
} else {
|
|
log.Println(info.Nicks[0], "added")
|
|
charsAdded++
|
|
}
|
|
|
|
for _, alt := range info.Nicks[1:] {
|
|
err := char.AddNick(alt)
|
|
if err != nil {
|
|
log.Println(info.Nicks[0], "failed to add nick", alt, "error:", err)
|
|
nicksFailed++
|
|
} else {
|
|
log.Println(info.Nicks[0], "addded nick", alt)
|
|
nicksAdded++
|
|
}
|
|
}
|
|
}
|
|
|
|
log.Printf("Characters – %d/%d", charsAdded, charsFailed+charsAdded)
|
|
log.Printf("Alt. Nicks – %d/%d", nicksAdded, nicksFailed+nicksAdded)
|
|
}
|