1 unstable release
0.1.0 | Dec 28, 2024 |
---|
#662 in Asynchronous
87 downloads per month
21KB
166 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]
aoc_leaderboard = "1.0.0"
or by running:
cargo add aoc_leaderboard
Example
use std::env;
use aoc_leaderboard::aoc::Leaderboard;
use dotenvy::dotenv;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Maybe your AoC token lives in a `.env` file?
let _ = dotenv();
// Fetch AoC session token and leaderboard ID from the environment.
let aoc_token = env::var("AOC_TOKEN")?;
let leaderboard_id = env::var("AOC_LEADERBOARD_ID")?.parse()?;
// 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, aoc_token).await?;
// Do something useful.
println!("Leaderboard for year {year} has {} members.", leaderboard.members.len());
Ok(())
}
The above example is available here. For complete API usage, see the docs.
Minimum Rust version
aoc_leaderboard
currently builds on Rust 1.70 or newer.
Dependencies
~1–12MB
~138K SLoC