Crates.io | libaoc |
lib.rs | libaoc |
version | 0.1.54 |
source | src |
created_at | 2024-12-09 06:22:30.265733 |
updated_at | 2024-12-12 10:09:37.425193 |
description | Advent of Code CLI |
homepage | |
repository | https://github.com/jocades/libaoc |
max_upload_size | |
id | 1476987 |
size | 80,674 |
Advent of Code CLI and utilities.
Handle puzzle retrieval, viewing and submission from the command line.
Get
the puzzle's questions and input. The contents are cached after every request / submission.Submit
the answer in a couple of key presses.View
the puzzle from the terminal or editor in markdown format.[!WARNING] An
AOC_AUTH_TOKEN
environment variable is required for user validation. See here.
cargo install libaoc
Retrieve the puzzle's questions and answers for a certain day and year.
aoc get -y 2024 -d 6
Submit an answer for a specific puzzle and part.
aoc submit -y 2024 -d 6 -p 2 "answer"
If the day or year is omitted, it will be derived from the current directory's structure. If the puzzle's part is omitted, it will smartly be chosen from the puzzle state. Almost all commands can be shortened in this way.
# /home/user/aoc/2024/d06
aoc submit "answer"
Take a look at the help.
aoc --help
Usage: aoc [OPTIONS] <COMMAND>
Commands:
get
submit
view
help Print this message or the help of the given subcommand(s)
Options:
-v, --verbose
-h, --help Print help
-V, --version Print version
A Rust client for the Advent of Code API. Reference.
cargo add libaoc
Use the client to get a puzzle from cache or by scraping the website.
use libaoc::Client;
let client = Client::new()?;
let id = (2024, 6); // `(year, day)`
let puzzle = client.get_puzzle(&id)?;
let input = client.get_input(&id?);
Download the puzzle, skip checking and saving to cache.
let puzzle = client.scrape_puzzle(&(2024, 6))?;
prinln!("Question: {}", puzzle.q1);
prinln!("Answer: {}", puzzle.a1);
Submit an answer.
let part = 2;
client.submit(&(2024, 6), part, "answer")?;
To correctly set your AOC_AUTH_TOKEN
environment variable, find the cookie
field in the request headers used when requesting a page, this one
for example, you can do so by opening the network panel
in your browser and
check for the field cookie
in the request headers of the current page. You
can also right click on the request and copy the cURL command used.
Remember that you must be logged in
for your session cookie to be present in your request headers.