Skip to content

Commit

Permalink
feat: add baron users registrator (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gornak40 committed May 30, 2024
1 parent 371cbe1 commit 5100b56
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

| Tool | Description | Ejudge | Polygon | Status |
| --- | --- | :---: | :---: | :---: |
| [baron](#baron) | register users to contest | 🦍 | ||
| [blanka](#blanka) | create contest | 🦍 | ||
| [boban](#boban) | filter runs | 🦍 | ||
| [casper](#casper) | change visibility | 🦍 | ||
Expand Down Expand Up @@ -61,6 +62,32 @@ Put your config file in `~/.config/algolymp/config.json`.
}
```

## baron
*Register users to Ejudge contest (Pending status).*

### About

Read user logins from `stdin` and register them to Ejudge contest.

Don't forget to set `OK` status manually!

### Flags
- `-i` - contest id (required)

### Config
- `ejudge.url`
- `ejudge.login`
- `ejudge.password`

### Examples
```bash
baron --help
baron -i 48501 # read from stdin
cat users.csv | baron -i 48600 # read from file
```

![baron logo](https://algolymp.ru/static/img/baron.png)

## blanka
*Create Ejuge contest from template.*

Expand Down
56 changes: 56 additions & 0 deletions cmd/baron/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"errors"
"fmt"
"io"
"os"

"github.com/Gornak40/algolymp/config"
"github.com/Gornak40/algolymp/ejudge"
"github.com/akamensky/argparse"
"github.com/sirupsen/logrus"
)

func main() {
parser := argparse.NewParser("baron", "Register users to Ejudge contest (Pending status).")
cID := parser.Int("i", "cid", &argparse.Options{
Required: true,
Help: "Ejudge contest ID",
})
if err := parser.Parse(os.Args); err != nil {
logrus.WithError(err).Fatal("bad arguments")
}

cfg := config.NewConfig()
ejClient := ejudge.NewEjudge(&cfg.Ejudge)

sid, err := ejClient.Login()
if err != nil {
logrus.WithError(err).Fatal("login failed")
}

csid, err := ejClient.MasterLogin(sid, *cID)
if err != nil {
logrus.WithError(err).Fatal("master login failed")
}

logrus.Info("waiting for logins input...")
for {
var login string
_, err := fmt.Scan(&login)
if errors.Is(err, io.EOF) {
break
}
if err != nil {
logrus.WithError(err).Fatal("invalid login")
}
if err := ejClient.RegisterUser(csid, login); err != nil {
logrus.WithError(err).Error("register user failed")
}
}

if err := ejClient.Logout(sid); err != nil {
logrus.WithError(err).Fatal("logout failed")
}
}
11 changes: 11 additions & 0 deletions ejudge/ejudge.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,14 @@ func (ej *Ejudge) MakeVisible(sid string, cid int) error {

return err
}

func (ej *Ejudge) RegisterUser(csid, login string) error {
logrus.WithFields(logrus.Fields{"CSID": csid, "login": login}).Info("register user")
_, _, err := ej.postRequest("new-master", url.Values{
"SID": {csid},
"action": {"20"},
"add_login": {login},
})

return err
}
Binary file added logos/baron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5100b56

Please sign in to comment.