Add unsubscribe-all flag

This commit is contained in:
Andrea Fazzi 2021-01-18 12:51:42 +01:00
parent 54f7971b16
commit 08dc821eb0

View file

@ -3,6 +3,7 @@ package main
import (
"flag"
"log"
"os"
"git.andreafazzi.eu/andrea/oef/client"
"git.andreafazzi.eu/andrea/oef/orm"
@ -21,6 +22,7 @@ func main() {
username := flag.String("username", "admin", "Username")
password := flag.String("password", "admin", "Password")
subscribe := flag.Bool("subscribe", true, "Subscribe to the given contest")
unsubscribeAll := flag.Bool("unsubscribe-all", false, "Unsubscribe all participants from all contests")
juniorContestId := flag.Int("jid", 0, "Contest ID for Junior category")
seniorContestId := flag.Int("sid", 0, "Contest ID for Senior category")
@ -40,6 +42,18 @@ func main() {
var updated bool
if *unsubscribeAll {
for _, participant := range participants {
participant.ContestIDs = make(orm.ContestIDs, 0)
id, err := client.Update(participant)
if err != nil {
panic(err)
}
log.Printf("Successfully updated participant ID %d", id)
}
os.Exit(0)
}
if *subscribe {
for _, participant := range participants {
for _, contest := range participant.Contests {