Skip to content

Commit

Permalink
perf: casper: logs into ejudge once; read ids from stdin (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gornak40 authored Jun 6, 2024
1 parent a098f6e commit d6d557b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ blanka -i 51013 -t 51000 -e
## boban
*Filter Ejudge runs.*

### Abount
### About

Filter and print Ejudge runs ids.

Expand All @@ -149,18 +149,16 @@ boban -i 50014 -c 10000 2> /dev/null | wc -l
![boban logo](https://algolymp.ru/static/img/boban.png)

## casper
*Change Ejudge contest visibility by id.*
*Change Ejudge contest visibility by ids.*

### About

- Make contest visible;
- Make contest invisible.
Read contest ids from `stdin` and make them invisible or visible.

Useful with bash `for` loop at the end of the year.
Useful with bash `seq`. Logs into Ejuge only once since `v0.14.2`.

### Flags
- `-i` - contest id (required)
- `-s` - make contest visible (invisible if not set)
- `-m` - invisible or visible (required, `hide|show`)

### Config
- `ejudge.url`
Expand All @@ -170,9 +168,9 @@ Useful with bash `for` loop at the end of the year.
### Examples
```bash
casper --help
casper -i 41014
casper -i 41014 -s
for i in {41014..41023}; do casper -i $i; done
echo 41014 | casper -m hide
seq 40301 40315 | casper -m show
casper -m hide # read from stdin
```

![casper logo](https://algolymp.ru/static/img/casper.png)
Expand Down Expand Up @@ -250,6 +248,7 @@ No config needed.
### Examples

```bash
fara --help
fara -f /home/judges/048025/conf/serve.cfg -q .score_system,virtual,contest_time
fara -f /home/judges/048025/conf/serve.cfg -q @problem.id,short_name,long_name
fara -f /home/judges/049013/conf/serve.cfg -q @problem.use_stdin,use_stdout -d
Expand Down
42 changes: 29 additions & 13 deletions cmd/casper/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

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

"github.com/Gornak40/algolymp/config"
Expand All @@ -9,15 +12,16 @@ import (
"github.com/sirupsen/logrus"
)

const (
makeInvisible = "hide"
makeVisible = "show"
)

func main() {
parser := argparse.NewParser("casper", "Change Ejudge contest visibility.")
cID := parser.Int("i", "cid", &argparse.Options{
parser := argparse.NewParser("casper", "Change Ejudge contests visibility (stdin input).")
mode := parser.Selector("m", "mode", []string{makeInvisible, makeVisible}, &argparse.Options{
Required: true,
Help: "Ejudge contest ID",
})
visible := parser.Flag("s", "show", &argparse.Options{
Required: false,
Help: "Make contest visible (invisible if flag is not set)",
Help: "Invisible or visible",
})
if err := parser.Parse(os.Args); err != nil {
logrus.WithError(err).Fatal("bad arguments")
Expand All @@ -31,14 +35,26 @@ func main() {
logrus.WithError(err).Fatal("login failed")
}

if *visible {
err = ejClient.MakeVisible(sid, *cID)
} else {
err = ejClient.MakeInvisible(sid, *cID)
var casperFunc func(string, int) error
switch *mode {
case makeVisible:
casperFunc = ejClient.MakeVisible
case makeInvisible:
casperFunc = ejClient.MakeInvisible
default:
logrus.WithField("mode", *mode).Fatal("unknown mode")
}

if err != nil {
logrus.WithError(err).Fatal("change visible status failed")
logrus.Info("waiting for contest ids input...")
for {
var cid int
_, err := fmt.Scan(&cid)
if errors.Is(err, io.EOF) {
break
}
if err := casperFunc(sid, cid); err != nil {
logrus.WithError(err).Fatal("change visible status failed")
}
}

if err := ejClient.Logout(sid); err != nil {
Expand Down

0 comments on commit d6d557b

Please sign in to comment.