From 72a31cd45df5c2cb663a7a77605ce2cd39232727 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Wed, 5 Feb 2020 12:39:51 +0100 Subject: [PATCH] Add script for export participants --- scripts/export_participants/.gitignore | 1 + scripts/export_participants/main.go | 36 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 scripts/export_participants/.gitignore create mode 100644 scripts/export_participants/main.go diff --git a/scripts/export_participants/.gitignore b/scripts/export_participants/.gitignore new file mode 100644 index 00000000..afed0735 --- /dev/null +++ b/scripts/export_participants/.gitignore @@ -0,0 +1 @@ +*.csv diff --git a/scripts/export_participants/main.go b/scripts/export_participants/main.go new file mode 100644 index 00000000..8a652fd8 --- /dev/null +++ b/scripts/export_participants/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "flag" + "os" + + "git.andreafazzi.eu/andrea/oef/client" + "git.andreafazzi.eu/andrea/oef/orm" + "github.com/gocarina/gocsv" +) + +func main() { + username := flag.String("username", "admin", "Username") + password := flag.String("password", "admin", "Password") + output := flag.String("output", "participants.csv", "Output filename") + + flag.Parse() + + client, err := client.Dial(flag.Arg(0), *username, *password) + if err != nil { + panic(err) + } + participants := make([]*orm.Participant, 0) + err = client.ReadAll(&participants) + if err != nil { + panic(err) + } + + f, err := os.Create(*output) + if err != nil { + panic(err) + } + defer f.Close() + + gocsv.MarshalFile(participants, f) +}