diff --git a/scripts/export_schools/.gitignore b/scripts/export_schools/.gitignore index cf2c6ef1..f724c097 100644 --- a/scripts/export_schools/.gitignore +++ b/scripts/export_schools/.gitignore @@ -1,2 +1,3 @@ *.csv *.xlsx +export_schools diff --git a/scripts/export_schools/export_schools b/scripts/export_schools/export_schools deleted file mode 100755 index 1fb1b1e4..00000000 Binary files a/scripts/export_schools/export_schools and /dev/null differ diff --git a/scripts/export_schools/main.go b/scripts/export_schools/main.go index 8bac1b96..2d585a63 100644 --- a/scripts/export_schools/main.go +++ b/scripts/export_schools/main.go @@ -12,6 +12,7 @@ import ( func main() { username := flag.String("username", "admin", "Username") password := flag.String("password", "admin", "Password") + noParticipants := flag.Bool("no-participants", false, "Filter schools with no participants") output := flag.String("output", "schools.csv", "Output filename") flag.Parse() @@ -32,5 +33,15 @@ func main() { } defer f.Close() + if *noParticipants { + filteredSchools := make([]*orm.School, 0) + for _, school := range schools { + if len(school.Participants) == 0 { + filteredSchools = append(filteredSchools, school) + } + } + schools = filteredSchools + } + gocsv.MarshalFile(schools, f) } diff --git a/scripts/resend_mail/.gitignore b/scripts/resend_mail/.gitignore new file mode 100644 index 00000000..0782955b --- /dev/null +++ b/scripts/resend_mail/.gitignore @@ -0,0 +1,4 @@ +*.csv +*.xlsx +*.log +resend_mail diff --git a/scripts/resend_mail/main.go b/scripts/resend_mail/main.go new file mode 100644 index 00000000..c3799f44 --- /dev/null +++ b/scripts/resend_mail/main.go @@ -0,0 +1,133 @@ +package main + +import ( + "flag" + "fmt" + "log" + "strings" + "time" + + "git.andreafazzi.eu/andrea/oef/client" + "git.andreafazzi.eu/andrea/oef/config" + "git.andreafazzi.eu/andrea/oef/mail" + "git.andreafazzi.eu/andrea/oef/orm" +) + +var mailBody = ` +Spettabile prof./prof.ssa {{.NameForMail}}, + +in seguito ad un controllo abbiamo verificato che la Vostra scuola +(cod. mec. {{.Username}}) non ha ancora iscritto alcun +partecipante. Qualora non avesse ricevuto le credenziali o le avesse +smarrite provvediamo a trasmetterle nuovamente. + +Di seguito riportiamo le credenziali di accesso tramite le quali potrà +gestire le iscrizioni dei Suoi studenti alla competizione (Fase +Regionale). + +username: {{.Username}} +password: {{.Password}} + +Per accedere alla pagina di login occorrerà seguire questo link + +https://piattaforma.oief.it/ + +ed inserire le credenziali riportate sopra (si consiglia di effettuare +un copia/incolla). + +Si ricorda che il termine ultimo per completare la procedura di +iscrizione dei partecipanti è il 05.03.2022. + +Questa mail è stata generata da un sistema automatico, si prega di non +rispondere. + +Cordialmente, +Lo Staff delle OIEF. +` + +type ContactPerson struct { + name string + username string + password string + email string +} + +func (model *ContactPerson) NameForMail() string { + return fmt.Sprintf("%s", model.name) +} + +func (model *ContactPerson) Username() string { + return strings.ToUpper(model.username) +} + +func (model *ContactPerson) Password() string { + return model.password +} + +func (model *ContactPerson) To() string { + return model.email +} + +func main() { + username := flag.String("username", "admin", "Username") + password := flag.String("password", "admin", "Password") + + flag.Parse() + + log.Println("Loading config file...") + + conf := new(config.ConfigT) + err := config.ReadFile("./config.yaml", conf) + if err != nil { + panic(err) + } + + client, err := client.Dial(flag.Arg(0), *username, *password) + if err != nil { + panic(err) + } + schools := make([]*orm.School, 0) + err = client.ReadAll(&schools) + if err != nil { + panic(err) + } + + log.Println("Get all users...") + + users := make([]*orm.User, 0) + err = client.ReadAll(&users) + if err != nil { + panic(err) + } + + mailSender := mail.NewMailSender(conf, mailBody) + + count := 0 + for _, school := range schools { + if len(school.Participants) == 0 { + log.Printf("[%d] Re-send email to school's contact person %s (%s)", count, school.SchoolContactPersonEmail, school.Name) + password := "" + for _, user := range users { + if user.ID == school.UserID { + password = user.Password + } + } + contactPerson := &ContactPerson{ + school.SchoolContactPersonLastname, + strings.TrimSpace(school.Code), + password, + school.SchoolContactPersonEmail, + } + + err := mailSender.SendSubscriptionMail(contactPerson) + if err != nil { + log.Println(err) + } + + time.Sleep(2 * time.Second) + + count++ + } + } + log.Printf("%d emails were sent!", count) +}