GraphQL API and utilities for the rpdata project
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

  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. "os"
  6. "git.aiterp.net/rpdata/api/internal/store"
  7. "git.aiterp.net/rpdata/api/model/character"
  8. )
  9. var fileName = flag.String("file", "./characters.json", "json file to load")
  10. func main() {
  11. file, err := os.Open(*fileName)
  12. if err != nil {
  13. log.Fatalln("Open:", err)
  14. }
  15. infos, err := load(file)
  16. if err != nil {
  17. log.Fatalln("Parse:", err)
  18. }
  19. err = store.Init()
  20. if err != nil {
  21. log.Fatalln("Store:", err)
  22. }
  23. charsAdded, charsFailed := 0, 0
  24. nicksAdded, nicksFailed := 0, 0
  25. for _, info := range infos {
  26. char, err := character.New(info.Nicks[0], info.Name, info.ShortName, info.Author, "")
  27. if err != nil {
  28. log.Println(info.Nicks[0], "failed to insert:", err)
  29. charsFailed++
  30. char, err = character.FindNick(info.Nicks[0])
  31. if err != nil {
  32. continue
  33. }
  34. } else {
  35. log.Println(info.Nicks[0], "added")
  36. charsAdded++
  37. }
  38. for _, alt := range info.Nicks[1:] {
  39. err := char.AddNick(alt)
  40. if err != nil {
  41. log.Println(info.Nicks[0], "failed to add nick", alt, "error:", err)
  42. nicksFailed++
  43. } else {
  44. log.Println(info.Nicks[0], "addded nick", alt)
  45. nicksAdded++
  46. }
  47. }
  48. }
  49. log.Printf("Characters – %d/%d", charsAdded, charsFailed+charsAdded)
  50. log.Printf("Alt. Nicks – %d/%d", nicksAdded, nicksFailed+nicksAdded)
  51. }