- cross-posted to:
- rust
- [email protected]
- learn_programming
- cross-posted to:
- rust
- [email protected]
- learn_programming
If you’re writing Advent of Code solutions in Rust, then I’ve written a crate that can fetch the user input data directly from the main website.
Long story short, you provide it a login token copied from your browser cookies, and it can fetch the input data by year and day. Inputs are cached locally, so it’ll only download it once for a given problem. This was heavily inspired by the PyPi advent-of-code-data package.
Unlike other AoC-centric Rust crates, that’s all it does. The other crates I’ve seen all want the code structured in a specific way to add timing benchmarks, unit testing, and other features. I wanted something lightweight where you just call a function to get the input; no more and no less.
To use the crate:
- Follow the AoCD instructions to set the AOC_SESSION environment variable.
This key is used for authentication and should not be shared with anyone. - Add the
aocfetch
crate to your Cargo.toml[
section: ]
aocfetch = { git = "https://github.com/ooterness/AdventOfCode.git" }
- Import the crate and call
aocfetch::get_data(year, day)
to fetch your input data.
An example:
use aocfetch;
fn main() {
let input = aocfetch::get_data(2023, 1).unwrap();
println!("My input data: {}", input);
println!("Part 1 solution: 42"); // TODO
println!("Part 2 solution: 42"); // TODO
}
If this goes well I will submit it to crates.io, but I wanted to open this up for beta-testing first.
Thanks, that’s a leftover from local testing. Will fix.