From 314603db64bb872107b178827657fc5e6a720928 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Wed, 3 May 2023 16:19:53 +0200 Subject: [PATCH] Export user credential by contest ID --- .gitignore | 3 +++ scripts/export_credentials/main.go | 24 ++++++++++++++++--- .../regions_contests.yaml | 12 +++++----- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 29357e44..17aa0612 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *~ oef +**/*.xlsx +**/*.ods + diff --git a/scripts/export_credentials/main.go b/scripts/export_credentials/main.go index 4b7635b9..54724704 100644 --- a/scripts/export_credentials/main.go +++ b/scripts/export_credentials/main.go @@ -20,6 +20,7 @@ func main() { username := flag.String("username", "admin", "Username") password := flag.String("password", "admin", "Password") output := flag.String("output", "credentials.csv", "Output filename") + cid := flag.Uint("cid", 0, "Export credentials of participants subscribed to the given contest") flag.Parse() @@ -38,9 +39,26 @@ func main() { panic(err) } - for _, user := range users { - if user.Role == "participant" { - credentials = append(credentials, &Credential{user.ID, user.Username, user.Password}) + if *cid != 0 { + log.Printf("Get participants subscribed to contest ID %v", *cid) + contest := new(orm.Contest) + contest.ID = *cid + _, err := client.Read(contest) + if err != nil { + panic(err) + } + for _, participant := range contest.Participants { + for _, user := range users { + if user.ID == participant.UserID { + credentials = append(credentials, &Credential{user.ID, user.Username, user.Password}) + } + } + } + } else { + for _, user := range users { + if user.Role == "participant" { + credentials = append(credentials, &Credential{user.ID, user.Username, user.Password}) + } } } diff --git a/scripts/subscribe_participants/regions_contests.yaml b/scripts/subscribe_participants/regions_contests.yaml index 47637d94..e10aa329 100644 --- a/scripts/subscribe_participants/regions_contests.yaml +++ b/scripts/subscribe_participants/regions_contests.yaml @@ -1,19 +1,19 @@ contests: - - id: 22 + - id: 30 category: Junior regions: [Basilicata,Calabria,Lombardia,Piemonte,Valle d'Aosta,Veneto] - - id: 23 + - id: 31 category: Senior regions: [Basilicata,Calabria,Lombardia,Piemonte,Valle d'Aosta,Veneto] - - id: 26 + - id: 32 category: Junior regions: [Campania,Emilia-Romagna,Friuli-Venezia Giulia,Liguria,Sardegna,Toscana,Trentino-Alto Adige] - - id: 27 + - id: 33 category: Senior regions: [Campania,Emilia-Romagna,Friuli-Venezia Giulia,Liguria,Sardegna,Toscana,Trentino-Alto Adige] - - id: 28 + - id: 34 category: Junior regions: [Abruzzo,Lazio,Marche,Molise,Puglia,Sicilia,Umbria] - - id: 25 + - id: 35 category: Senior regions: [Abruzzo,Lazio,Marche,Molise,Puglia,Sicilia,Umbria]