🎄 Advent of Code command-line tool.

Overview

🎄 advent-cli

advent-cli is a command-line tool for interacting with Advent of Code, specifically geared toward writing solutions in Python. It can be used to view puzzle prompts, download input, submit solutions, and view personal or private stats and leaderboards.

Installation

Clone this repository and simply run:

pip install .

(PyPI installation coming soon)

Configuration

Before you do anything, you'll need to provide advent-cli with a session cookie so it can authenticate as you. To do this, log in to the Advent of Code website and grab the cookie named session from your browser's inspect element tool. Store it in an environment variable on your machine named ADVENT_SESSION_COOKIE. A fresh session cookie is good for about a month, after which you'll need to repeat these steps.

Full list of configuration environment variables:

Variable Function
ADVENT_SESSION_COOKIE Advent of Code session cookie for authentication.
ADVENT_PRIV_BOARDS Comma-separated list of private leaderboard IDs. (optional)
ADVENT_DISABLE_TERMCOLOR Set to 1 to permanently disable coloring terminal output. (optional)

Usage

advent-cli can be invoked using the advent command, or python -m advent_cli.

Download a question

$ advent get YYYY/DD

This will create the directory YYYY/DD (e.g. 2021/01) inside the current working directory. Inside, you'll find part 1 of the puzzle prompt in prompt.md, your puzzle input in input.txt, and a generated solution template in solution.py. More about that here.

Test a solution

$ advent test YYYY/DD

This will run the solution file in the directory YYYY/DD and print the output without actually submitting. Use this to debug or check for correctness. Optional flags:

  • -e, --example: Test the solution using example_input.txt. This is an empty file that gets created when you run advent get where you can manually store the example input from the puzzle prompt. Useful for checking solutions for correctness before submitting.
  • -f, --solution-file: Test a solution file other than solution.py (e.g. -f solution2 to run solution2.py). This will assume you already have a working solution in solution.py and check the new file's output against it. Useful for testing alternate solutions after you've already submitted since you cannot re-submit.

Submit answers

$ advent submit YYYY/DD

This will run the solution file in the directory YYYY/DD and automatically attempt to submit the computed answers for that day. After implementing part 1, run this command to submit part 1 and (if correct) append the prompt for part 2 to prompt.md. Run again after implementing part 2 to submit part 2. Optional flags:

  • -f, --solution-file: Submit using a solution file other than solution.py (e.g. -f solution2 to run solution2.py). This can only be done if a correct answer hasn't already been submitted.

Check personal stats

$ advent stats YYYY

This will print out your progress for the year YYYY and output the table found on adventofcode.com/{YYYY}/leaderboard/self with your time, rank, and score for each day and part.

Check private leaderboards

$ advent stats YYYY --private

This will print out each of the private leaderboards given in ADVENT_PRIV_BOARDS. Also works with -p.

Solution structure

advent-cli expects the following directory structure (example):

2020/
 └─ 01/
     └─ example_input.txt
     └─ input.txt
     └─ prompt.md
     └─ solution.py
     └─ [alternate solution files]
 └─ 02/
     └─ ...
 └─ ...
2021/
 └─ 01/
     └─ ...
 └─ ...

The solution.py file will look like this when first generated:

## advent of code {year}
## https://adventofcode.com/{year}
## day {day}

def parse_input(lines):
    pass

def part1(data):
    pass

def part2(data):
    pass

When the solution is run, the input will be read from input.txt and automatically passed to parse_input as lines, an array of strings where each string is a line from the input with newline characters removed. You should implement parse_input to return your parsed input or inputs, which will then be passed to part1 and part2. If parse_input returns a tuple, part1 and part2 will be expecting multiple parameters that map to those returned values. The parameter names can be changed to your liking. The only constraint is that part1 and part2 must have the same number of parameters.

If part2 is left unmodified or otherwise returns None, it will be considered unsolved and part1 will be run and submitted. If both functions are implemented, part2 will be submitted.

Credits

This started out as a simple script which was inspired by Hazel and haskal.

License

advent-cli is distributed under the GNU GPL-3.0 License.

You might also like...
PyArmor is a command line tool used to obfuscate python scripts

PyArmor is a command line tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.

A command line tool to remove background from video and image
A command line tool to remove background from video and image

A command line tool to remove background from video and image, brought to you by BackgroundRemover.app which is an app made by nadermx powered by this tool

Amazon Scraper: A command-line tool for scraping Amazon product data
Amazon Scraper: A command-line tool for scraping Amazon product data

Amazon Product Scraper: 2021 Description A command-line tool for scraping Amazon product data to CSV or JSON format(s). Requirements Python 3 pip3 Ins

A command line tool (and Python library) for archiving Twitter JSON

A command line tool (and Python library) for archiving Twitter JSON

command line tool for frequent nmigen tasks (generate sources, show design)
command line tool for frequent nmigen tasks (generate sources, show design)

nmigen-tool command line tool for frequent nmigen tasks (generate sources, show design) Usage: generate verilog: nmigen generate verilog nmigen_librar

Command line tool to keep track of your favorite playlists on YouTube and many other places.

Command line tool to keep track of your favorite playlists on YouTube and many other places.

googler is a power tool to Google (web, news, videos and site search) from the command-line.
googler is a power tool to Google (web, news, videos and site search) from the command-line.

googler is a power tool to Google (web, news, videos and site search) from the command-line.

LSD (Linux Spotify Downloader) is a command line tool for downloading or rather recording content on Spotify.
LSD (Linux Spotify Downloader) is a command line tool for downloading or rather recording content on Spotify.

LSD (Linux Spotify Downloader) is a command line tool for downloading or rather recording content on Spotify.

Command line tool for google dorks

CLI for google dorks This is the command line tool made with pytohn which allows the users to perform Google dorks easily Installation Install google

Comments
  • `parse_input` does not currently support Generators

    `parse_input` does not currently support Generators

    It is quite common to use generators to handle input parsing:

    def parse_input(lines: list[str]):
        for line in lines:
           yield re.match('...', line).groups()
    

    Currently, this does not work as the runner passes the same generator into Part 1 and Part 2, which is exhausted in Part 2 as it has already been iterated in Part 1.

    This can be implemented relatively easily if desired by detecting a Generator with isinstance and making a copy for Part 2.

    enhancement 
    opened by ionite34 3
  • Please read: AoC 2022 - Contributing

    Please read: AoC 2022 - Contributing

    advent-cli users,

    I haven't had much time this year to maintain this tool or make updates that I've been wanting to make, and that will likely be the case for the remainder of the year. I'm still around though, and I want this project to keep going - so if something has broken or there's a feature you really want added for this year's comp, feel free to submit a pull request and I'll gladly look over it.

    Happy coding and happy holidays!

    opened by fergusch 0
Releases(v0.2.2)
  • v0.2.2(Feb 3, 2022)

  • v0.2.1(Dec 24, 2021)

    Changes

    Features

    • Added conversion of inline <em> tags
    • Added error messages if session cookie is invalid or expired
    • countdown now returns a non-zero exit code if aborted, preventing any get commands chained with && from running

    Full changelog

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Dec 17, 2021)

    Changes

    Features

    • Added countdown command
    • Added config options for converting <em> tags to markdown
    • Private leaderboards owned by the user are now supported
    • stats command now defaults to the current year if not specified

    Bug fixes

    • Fixed a layout issue when displaying private leaderboards

    Full changelog

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Dec 11, 2021)

    Changes

    Features

    • advent-cli is now on PyPI! 🎉
    • Improved error handling

    Bug fixes

    • Fixed an issue where --version would output __main__ instead of advent-cli when run with python -m
    • Fixed an issue where submit would overwrite part 1 in prompt.md after downloading part 2
    • Fixed an issue where pip would not install requirements due to a typo in setup.cfg
    • Fixed an issue where get would not create directories

    Other

    • Lowered minimum Python version to 3.7
    • Added unit tests

    Full changelog

    Source code(tar.gz)
    Source code(zip)
Owner
Christian Ferguson
i'm the cat
Christian Ferguson
py-image-dedup is a tool to sort out or remove duplicates within a photo library

py-image-dedup is a tool to sort out or remove duplicates within a photo library. Unlike most other solutions, py-image-dedup intentionally uses an approximate image comparison to also detect duplica

Markus Ressel 96 Jan 02, 2023
A simple command line dumper written in Python 3.

A simple command line dumper written in Python 3.

ImFatF1sh 1 Oct 10, 2021
A Command Line Error Parser Built using Python.

"Stalk Overflow with debuggy" Error Parser Everything is done in Python so it's extremely easy to install and use. Supports Python 3. Debuggy is used

Derhnyel 22 Nov 10, 2022
Pastekan adalah website paste kode / teks sederhana

Pastekan pastekan adalah website paste kode / teks sederhana. install pip install pastekan penggunaan pastekan myfile.txt atau echo "hi" | pastekan

Sekai Kode 1 Dec 24, 2021
Play Wordle Bot - Wordle Bot written in python

Wordle Bot A Bot written in python with a CL Interface to guess adn solve Wordle

Prashant 1 Feb 25, 2022
CLI tool to computes CO2 emissions of HPC computations following green-algorithms.org methodology

gqueue gqueue is a CLI (command line interface) tool that computes carbon footprint of HPC computations on clusters running slurm. It follows the meth

4 Dec 10, 2021
Tool for HackMyVM platform

HMV-cli It is a tool for the HackMyVM platform. With this tool you will be able to see the machines you have pending, filter by difficulty, download d

bitc0de 11 Sep 19, 2022
Proman is a simple tool for managing projects through cli.

proman proman is a project manager. It helps you manage your projects from a terminal. The features are listed below. Installation Step 1: Download or

Arjun Somvanshi 2 Dec 06, 2021
A dec-bin converter uses 2's complement.

2's Complement Dec-Bin Converter A dec-bin converter uses 2's complement. Visit my Medium Post. What is 2's complement? Two's complement is the most c

C.H Jacky 9 Mar 01, 2022
A tool to manage the study of courses at the university.

todo-cli A tool to manage the study of courses at the university

Quentin 6 Aug 01, 2022
Fetch is use to get information about anything on the shell using Wikipedia.

Fetch Search wikipedia article on command line [Why This?] [Support the Project] [Installation] [Configuration] Why this? Fetch helps you to quickly l

Yash Singh 340 Dec 18, 2022
Splitgraph command line client and python library

Splitgraph Overview Splitgraph is a tool for building, versioning and querying reproducible datasets. It's inspired by Docker and Git, so it feels fam

Splitgraph 313 Dec 24, 2022
stonky is a simple command line dashboard for monitoring stocks.

stonky is a simple command line dashboard for monitoring stocks.

Jessy Williams 228 Dec 14, 2022
A user-friendly python CLI for Fmask 4.3 software (GERS Lab, UCONN).

pyFmask What is pyFmask pyFmask is a user-friendly python CLI for Fmask 4.3 software (GERS Lab, UCONN; https://github.com/GERSL/Fmask). Fmask (Zhu et

1 Jan 05, 2022
Lexeme - CLI to play a word-guessing game like Wordle

What is this? Python program to play a word-guessing game like Wordle, but… More addictive because you can play it over and over and over, not just on

Dan Lenski 6 Oct 26, 2022
TerminalGV is a very simple client to display stats about your SNCF TGV/TER train in your terminal.

TerminalGV So I got bored in the train, TerminalGV is a very simple client to display stats about your SNCF TGV/TER train in your terminal. The "on-tr

Samuel 8 Dec 15, 2022
As easy as /aitch-tee-tee-pie/ 🥧 Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more. https://twitter.com/httpie

HTTPie: human-friendly CLI HTTP client for the API era HTTPie (pronounced aitch-tee-tee-pie) is a command-line HTTP client. Its goal is to make CLI in

HTTPie 25.4k Dec 30, 2022
A simple script that outputs the current date on the user interface/terminal.

Py-Date A simple script that outputs the current date on the user interface/terminal. How to Run Open your terminal and cd into the folder containi

Arinzechukwu Okoye 1 Jan 13, 2022
Command line tool to keep track of your favorite playlists on YouTube and many other places.

Command line tool to keep track of your favorite playlists on YouTube and many other places.

Wolfgang Popp 144 Jan 05, 2023
Simple Python Library to display text with color in Python Terminal

pyTextColor v1.0 Introduction pyTextColor is a simple Python Library to display colorful outputs in Terminal, etc. Note: Your Terminal or any software

Siddhesh Chavan 1 Jan 23, 2022