Add export_credentials script
This commit is contained in:
parent
f72b65409b
commit
cb841a8b01
3 changed files with 80 additions and 1 deletions
5
scripts/export_credentials/.gitignore
vendored
Normal file
5
scripts/export_credentials/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
test_credentials
|
||||||
|
*.csv
|
||||||
|
*.xlsx
|
||||||
|
export_credentials
|
||||||
|
|
55
scripts/export_credentials/main.go
Normal file
55
scripts/export_credentials/main.go
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.andreafazzi.eu/andrea/oef/client"
|
||||||
|
"git.andreafazzi.eu/andrea/oef/orm"
|
||||||
|
"github.com/gocarina/gocsv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Credential struct {
|
||||||
|
ID uint
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
username := flag.String("username", "admin", "Username")
|
||||||
|
password := flag.String("password", "admin", "Password")
|
||||||
|
output := flag.String("output", "rank.csv", "Output filename")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
client, err := client.Dial(flag.Arg(0), *username, *password)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
users := make([]*orm.User, 0)
|
||||||
|
credentials := make([]*Credential, 0)
|
||||||
|
|
||||||
|
log.Println("Get all users...")
|
||||||
|
|
||||||
|
err = client.ReadAll(&users)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, user := range users {
|
||||||
|
if user.Role == "participant" {
|
||||||
|
credentials = append(credentials, &Credential{user.ID, user.Username, user.Password})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Create(*output)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
gocsv.MarshalFile(credentials, f)
|
||||||
|
|
||||||
|
}
|
|
@ -78,6 +78,7 @@ func main() {
|
||||||
password := flag.String("password", "admin", "Password")
|
password := flag.String("password", "admin", "Password")
|
||||||
output := flag.String("output", "rank.csv", "Output filename")
|
output := flag.String("output", "rank.csv", "Output filename")
|
||||||
contestId := flag.Int("id", 0, "Contest ID")
|
contestId := flag.Int("id", 0, "Contest ID")
|
||||||
|
all := flag.Bool("all", false, "Rank all participants")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Score > 0 && r.Duration > 0 {
|
if r.Score > 0 && r.Duration > 0 && !*all {
|
||||||
school, err := findSchool(schools, r.Participant.SchoolID)
|
school, err := findSchool(schools, r.Participant.SchoolID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -136,6 +137,24 @@ func main() {
|
||||||
Duration: uint(r.Duration / time.Second),
|
Duration: uint(r.Duration / time.Second),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
school, err := findSchool(schools, r.Participant.SchoolID)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
csvResponses = append(
|
||||||
|
csvResponses,
|
||||||
|
&Response{
|
||||||
|
Firstname: r.Participant.Firstname,
|
||||||
|
Lastname: r.Participant.Lastname,
|
||||||
|
FiscalCode: r.Participant.FiscalCode,
|
||||||
|
School: school.String(),
|
||||||
|
Region: school.Region.String(),
|
||||||
|
Score: r.Score,
|
||||||
|
Duration: uint(r.Duration / time.Second),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue