From dcb10f730f87099357b65c503285ac376c270f45 Mon Sep 17 00:00:00 2001 From: Gornak40 Date: Sun, 17 Nov 2024 15:05:14 +0300 Subject: [PATCH] chore: dump regs --- README.md | 27 +++++++++++++++++++-------- cmd/shoga/main.go | 7 +++++-- ejudge/dumps.go | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6fbcee5..0347d3c 100644 --- a/README.md +++ b/README.md @@ -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 | | ๐Ÿฆ | โœ… | @@ -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` @@ -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) diff --git a/cmd/shoga/main.go b/cmd/shoga/main.go index 94381d0..ba9fbb7 100644 --- a/cmd/shoga/main.go +++ b/cmd/shoga/main.go @@ -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", @@ -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 { diff --git a/ejudge/dumps.go b/ejudge/dumps.go index 7de3acc..afa9dee 100644 --- a/ejudge/dumps.go +++ b/ejudge/dumps.go @@ -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)