|
|
package main
import ( "flag" "log" "os"
"git.aiterp.net/rpdata/api/internal/store" "git.aiterp.net/rpdata/api/models/characters" )
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 := characters.Add(info.Nicks[0], info.Name, info.ShortName, info.Author, "") if err != nil { log.Println(info.Nicks[0], "failed to insert:", err) charsFailed++
char, err = characters.FindNick(info.Nicks[0]) if err != nil { continue } } else { log.Println(info.Nicks[0], "added") charsAdded++ }
for _, alt := range info.Nicks[1:] { char, err = characters.AddNick(char, 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) }
|