Skip to content

Instantly share code, notes, and snippets.

@tors42
Created February 18, 2024 14:21
Show Gist options
  • Save tors42/d85a1f6d1a081725e23da2f662a930d6 to your computer and use it in GitHub Desktop.
Save tors42/d85a1f6d1a081725e23da2f662a930d6 to your computer and use it in GitHub Desktop.
Download Team Arena and Swiss PGNs
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.83/chariot-0.0.83.jar"
).toURL().openStream().readAllBytes());
}
/env --class-path chariot.jar
import chariot.Client;
import chariot.model.*
import java.io.*;
import java.nio.file.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
String teamId = "coders"; // https://lichess.org/team/coders
int maxArenas = 1;
int maxSwisses = 1;
boolean evals = false;
boolean clocks = false;
var client = Client.basic();
// var client = Client.auth("lip_token"); // faster download, but needs a token
if (client.teams().byTeamId(teamId) instanceof Fail<?> fail) {
System.out.println("Failed to find team " + teamId + "\n" + fail);
System.exit(1);
}
Path arenas = Path.of(teamId, "arenas");
Path swisses = Path.of(teamId, "swiss");
Files.createDirectories(arenas);
Files.createDirectories(swisses);
var counter = new AtomicInteger();
client.teams().arenaByTeamId(teamId, maxArenas).stream().forEach(arena -> {
try {
Files.writeString(
arenas.resolve(counter.incrementAndGet() + "-" + arena.id() + ".pgn"),
client.tournaments().pgnGamesByArenaId(arena.id(), params -> params.
evals(evals).
clocks(clocks)).
stream().
map(Pgn::toString).
collect(Collectors.joining("\n\n")));
} catch (IOException ioe) { throw new UncheckedIOException(ioe); }
});
counter.set(0);
client.teams().swissByTeamId(teamId, maxSwisses).stream().forEach(swiss -> {
try {
Files.writeString(
swisses.resolve(counter.incrementAndGet() + "-" + swiss.id() + ".pgn"),
client.tournaments().pgnGamesBySwissId(swiss.id(), params -> params.
evals(evals).
clocks(clocks)).
stream().
map(Pgn::toString).
collect(Collectors.joining("\n\n")));
} catch (IOException ioe) { throw new UncheckedIOException(ioe); }
});
/exit
@tors42
Copy link
Author

tors42 commented Feb 18, 2024

Run with jshell which comes with Java. Can be downkloaded at https://jdk.java.net/21 for instance.

$ jshell tournaments.jsh
$ ls coders/arenas/
1-QQDJENHA.pgn
$ ls coders/swiss/
1-5M5GxDJm.pgn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment