Skip to content

Commit

Permalink
chore: dump regs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gornak40 committed Nov 17, 2024
1 parent 13b086e commit dcb10f7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Extended release notes can be found at [chat](https://t.me/algolymp).
| [pepel](#pepel) | generate hasher solution | | ||
| [ripper](#ripper) | change runs status | 🦍 | ||
| [scalp](#scalp) | incremental scoring | | 🦍 ||
| [shoga](#shoga) | dump registered users | 🦍 | ||
| [shoga](#shoga) | dump contest tables | 🦍 | ||
| [valeria](#valeria) | valuer.cfg + tex scoring | | 🦍 ||
| [vydra](#vydra) | upload package | | 🦍 | 🧪 |
| [wooda](#wooda) | glob problem files upload | | 🦍 ||
Expand Down Expand Up @@ -477,17 +477,25 @@ scalp -i 330328 -s
![scalp logo](https://algolymp.ru/static/img/scalp.png)

## shoga
*Dump Ejudge contest users.*
*Dump Ejudge contest tables.*

### About

Print Ejudges users who registered in the specified contest (CSV format).
Print Ejudges contest tables (CSV format). Various modes are supported.

You can use some custom CSV toolkits, like [xsv](https://github.com/BurntSushi/xsv.git) or [qsv](https://github.com/jqnatividad/qsv.git) to process the output. But I prefer to use vanilla [awk](https://manpages.org/awk) or [cut](https://manpages.org/cut).
**Tip:** You can use some custom CSV toolkits, like [xsv](https://github.com/BurntSushi/xsv.git) or [qsv](https://github.com/jqnatividad/qsv.git) to process the output. But I prefer to use vanilla [awk](https://manpages.org/awk) or [cut](https://manpages.org/cut).

#### Supported modes

- `usr` - registered users
- `run` - contest runs
- `stn` - contest standings
- `prb` - contest problems
- `reg` - registration passwords

### Flags
- `-i` - contest id (required)
- `-m` - dump mode (required, `usr|run|stn`)
- `-m` - dump mode (required, `usr|run|stn|prb|reg`)

### Config
- `ejudge.url`
Expand All @@ -497,12 +505,15 @@ You can use some custom CSV toolkits, like [xsv](https://github.com/BurntSushi/x
### Examples
```bash
shoga --help
shoga -i 59000 -m usr # all registered users
shoga -i 59000 -m usr # registered users
shoga -i 59000 -m usr | awk '{split($0,a,";"); print a[2]}' # just registered logins
shoga -i 60705 -m usr | cut -d ';' -f 2 | tail -n +2 | sort # just registered logins
shoga -i 55000 -m run # all contest runs
shoga -i 55000 -m run # contest runs
shoga -i 436 -m stn # full standings
shoga -i 436 -m stn | cut -d ";" -f 1,2,9,10 | head -n -3 # 6 problems acm contest finals
shoga -i 436 -m stn | cut -d ";" -f 1,2,9,10 | head -n -3 # 6 problems acm contest standings
shoga -i 48005 -m prb # contest problems
shoga -i 51000 -m reg # registration passwords
shoga -i 51000 -m reg | grep shkuleva | cut -d ';' -f 3,6 # specified password
```

![shoga logo](https://algolymp.ru/static/img/shoga.png)
Expand Down
7 changes: 5 additions & 2 deletions cmd/shoga/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ const (
modeRuns = "run"
modeStandings = "stn"
modeProblems = "prb"
modePasswords = "reg"
)

func main() {
parser := argparse.NewParser("shoga", "Dump Ejudge contest users.")
parser := argparse.NewParser("shoga", "Dump Ejudge contest tables.")
cID := parser.Int("i", "cid", &argparse.Options{
Required: true,
Help: "Ejudge contest ID",
})
av := []string{modeUsers, modeRuns, modeStandings, modeProblems}
av := []string{modeUsers, modeRuns, modeStandings, modeProblems, modePasswords}
mode := parser.Selector("m", "mode", av, &argparse.Options{
Required: true,
Help: "Dump mode",
Expand Down Expand Up @@ -55,6 +56,8 @@ func main() {
call = ejClient.DumpStandings
case modeProblems:
call = ejClient.DumpProbStats
case modePasswords:
call = ejClient.DumpRegPasswords
}
r, err := call(csid)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions ejudge/dumps.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ func (ej *Ejudge) DumpProbStats(csid string) (io.Reader, error) {
return walkTable(th)
}

func (ej *Ejudge) DumpRegPasswords(csid string) (io.Reader, error) {
logrus.WithFields(logrus.Fields{
"CSID": csid,
}).Info("dump registration passwords")
_, doc, err := ej.postRequest(newMaster, url.Values{
"SID": {csid},
"action": {"120"},
})
if err != nil {
return nil, err
}
th := doc.Find(".b1 > tbody > tr")

return walkTable(th)
}

func walkTable(table *goquery.Selection) (io.Reader, error) {
bf := bytes.NewBuffer(make([]byte, 0, defBufSize))
w := csv.NewWriter(bf)
Expand Down

0 comments on commit dcb10f7

Please sign in to comment.