10 releases

new 0.1.54 Dec 12, 2024
0.1.53 Dec 10, 2024

#831 in Command line utilities

Download history 1473/week @ 2024-12-09

1,473 downloads per month

MIT license

23KB
557 lines

libaoc

Advent of Code CLI and utilities.

Crates.io MIT licensed

CLI

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.

Install

cargo install libaoc

Example

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
Show output.
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

API

A Rust client for the Advent of Code API. Reference.

Install

cargo add libaoc

Example

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")?;

Session token

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.

Dependencies

~14–26MB
~387K SLoC