2023-03-15 07:53:36 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.tilde.town/tildetown/town/models"
|
|
|
|
"git.tilde.town/tildetown/town/signup"
|
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
|
|
)
|
|
|
|
|
2023-03-15 08:16:16 +00:00
|
|
|
// TODO ok so right now this just does one hyper specific thing, but I want to
|
|
|
|
// add more similar scripts here. this might warrant the introduction of cobra.
|
|
|
|
|
2023-03-15 07:53:36 +00:00
|
|
|
func confirmContinue(msg string) {
|
|
|
|
var serr error
|
|
|
|
var conf bool
|
|
|
|
if serr = survey.AskOne(&survey.Confirm{
|
|
|
|
Message: msg,
|
|
|
|
Default: false,
|
|
|
|
}, &conf); serr != nil {
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
if !conf {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type jsonSignup struct {
|
2023-03-15 08:11:55 +00:00
|
|
|
Created float64
|
|
|
|
Email string
|
2023-03-15 07:53:36 +00:00
|
|
|
Username string
|
|
|
|
Reasons string
|
|
|
|
Plans string
|
|
|
|
Referral string
|
|
|
|
Socials string
|
|
|
|
Notes string
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
lol, err := os.ReadFile("/town/var/signups.json")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
db, err := signup.ConnectDB()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
lines := strings.Split(string(lol), "\n")
|
|
|
|
errs := []error{}
|
|
|
|
signups := make([]jsonSignup, len(lines))
|
|
|
|
for i, l := range lines {
|
2023-03-15 08:13:44 +00:00
|
|
|
l = strings.TrimSpace(l)
|
|
|
|
if l == "" {
|
|
|
|
continue
|
|
|
|
}
|
2023-03-15 07:53:36 +00:00
|
|
|
s := jsonSignup{}
|
|
|
|
err := json.Unmarshal([]byte(l), &s)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s %s", l, err.Error())
|
|
|
|
errs = append(errs, err)
|
|
|
|
} else {
|
|
|
|
signups[i] = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(errs) > 0 {
|
|
|
|
confirmContinue(fmt.Sprintf("%d errors found deserializing; continue?", len(errs)))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range signups {
|
|
|
|
ts := models.TownSignup{
|
|
|
|
Created: time.Unix(int64(s.Created), 0),
|
2023-03-15 08:11:55 +00:00
|
|
|
Email: s.Email,
|
2023-03-15 07:53:36 +00:00
|
|
|
How: s.Referral,
|
|
|
|
Why: s.Reasons + "\n" + s.Plans,
|
|
|
|
Links: s.Socials,
|
|
|
|
}
|
|
|
|
if err = ts.Insert(db); err != nil {
|
|
|
|
confirmContinue(fmt.Sprintf("%#v led to error %s; continue?", ts, err.Error()))
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.Notes != "" {
|
2023-03-15 08:25:06 +00:00
|
|
|
note := models.SignupNote{
|
|
|
|
Created: time.Now(),
|
|
|
|
Author: "IMPORT",
|
|
|
|
Content: s.Notes,
|
|
|
|
SignupID: ts.ID,
|
2023-03-15 07:53:36 +00:00
|
|
|
}
|
2023-03-15 08:25:06 +00:00
|
|
|
if err = note.Insert(db); err != nil {
|
2023-03-15 07:53:36 +00:00
|
|
|
confirmContinue(fmt.Sprintf("%#v led to error %s; continue?", ts, err.Error()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|