5 releases (2 stable)
Uses new Rust 2024
| 2.0.0 | Nov 28, 2025 |
|---|---|
| 1.0.0 | Nov 27, 2025 |
| 0.3.0 | Nov 27, 2025 |
| 0.2.0 | Jan 19, 2025 |
| 0.1.0 | Dec 28, 2024 |
#962 in Asynchronous
Used in 4 crates
33KB
455 lines
aoc_leaderboard
Strongly-typed wrapper for an Advent of Code leaderboard and a convenient way to fetch its data.
Installing
Add aoc_leaderboard to your dependencies:
[dependencies]
# Enable http feature to be able to fetch leaderboard data
aoc_leaderboard = { version = "2.0.0", features = ["http"] }
or by running:
cargo add aoc_leaderboard --features http
Example
use std::env;
use aoc_leaderboard::aoc::{Leaderboard, LeaderboardCredentials};
use dotenvy::dotenv;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Maybe your config lives in a `.env` file?
let _ = dotenv();
// Fetch leaderboard ID and AoC credentials from the environment.
let leaderboard_id = env::var("AOC_LEADERBOARD_ID")?.parse()?;
let credentials = aoc_credentials()?;
// Load the leaderboard from the AoC website.
// Careful not to call this more than once every **15 minutes**.
let year = 2024;
let leaderboard = Leaderboard::get(year, leaderboard_id, &credentials).await?;
// Do something useful.
println!("Leaderboard for year {year} has {} members.", leaderboard.members.len());
Ok(())
}
fn aoc_credentials() -> anyhow::Result<LeaderboardCredentials> {
Ok(env::var("AOC_VIEW_KEY")
.map(LeaderboardCredentials::ViewKey)
.or_else(|_| env::var("AOC_SESSION").map(LeaderboardCredentials::SessionCookie))?)
}
The above example is available here. For complete API usage, see the docs.
Minimum Rust version
aoc_leaderboard currently builds on Rust 1.88 or newer.
Contributing / Local development
For information about contributing to this project, see CONTRIBUTING. For information regarding local development, see DEVELOPMENT.
Dependencies
~1–18MB
~163K SLoC