🎄 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
A lightweight Python module and command-line tool for generating NATO APP-6(D) compliant military symbols from both ID codes and natural language names

Python military symbols This is a lightweight Python module, including a command-line script, to generate NATO APP-6(D) compliant military symbol icon

Nick Royer 5 Dec 27, 2022
CLI tool to show the current crypto balance

CryptoBoard The simple python CLI tool for one currency to show the current crypto balance yours purchases. That's all. Data source is from https://ww

John 2 Nov 18, 2021
A command line connect 4 game against a minimax agent.

A command line connect 4 game against a minimax agent.

1 Oct 17, 2021
3DigitDev 29 Jan 17, 2022
Cli tool to browse and play anime

browse and watch anime (scrape from gogoanime) (wip) basically ani-cli but in python cuz python good demo dependencies mpv installation from pypi pip

sheep padowo 2 Apr 20, 2022
Wordle for CLUE - WORDLE clone for Adafruit Clue

Wordle_for_CLUE This project is a clone of the very popular word solving puzzle

Michael Lacock 4 Feb 15, 2022
doq (python docstring generator) extension for coc.nvim

coc-pydocstring doq (python docstring generator) extension for coc.nvim Install CocInstall: :CocInstall coc-pydocstring vim-plug: Plug 'yaegassy/coc-p

yaegassy 27 Jan 04, 2023
A command line tool made in Python for the popular rhythm game

osr!name A command line tool made in Python for the popular rhythm game "osu!" that changes the player name of a .osr file (replay file). Example: Not

2 Dec 28, 2021
A CLI/Shell supporting OpenRobot API and more!

A CLI/Shell supporting JeyyAPI, OpenRobot API and RePI API.

OpenRobot Packages 1 Jan 06, 2022
A fantasy life simulator and role-playing game hybrid distributed as CLI, written in Python 3.

Life is Fantasy Epic (LIFE) A fantasy life simulator and role-playing game hybrid distributed as CLI, written in Python 3. This repository will be pro

Pawitchaya Chaloeijanya 2 Oct 24, 2021
👻 Ghoul is an easy to use information service, allowing you to get/add information on someone or something directly from your terminal.

👻 Ghoul is an easy to use information service, allowing you to get/add information on someone or something directly from your terminal. It c

Billy 11 Nov 10, 2021
Chat In Terminal - Chat-App in python

Chat In Terminal Hello all. 😉 Sockets and servers are vey important for connection and importantly chatting with others. 😂 😁 I have thought of maki

Shreejan Dolai 5 Nov 17, 2022
CLI program that allows you to change your Alacritty config with one command without editing the config file.

Pycritty Change your alacritty config on the fly! Installation: pip install pycritty By default, only the program itself will be installed, but you ca

Antonio Sarosi 184 Jan 07, 2023
Joji convert a text to corresponding emoji if emoji is available

Joji Joji convert a text to corresponding emoji if emoji is available How it Works ? 1. There is a json file with emoji names as keys and correspondin

Gopikrishnan Sasikumar 28 Nov 26, 2022
Dark powered asynchronous completion framework for neovim/Vim8

deoplete.nvim Dark powered asynchronous completion framework for neovim/Vim8 Note: The development of this plugin is finished. Accepts minor patches a

Shougo 5.9k Dec 30, 2022
A simple command line dumper written in Python 3.

A simple command line dumper written in Python 3.

ImFatF1sh 1 Oct 10, 2021
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
An open-source CLI tool for backing up RDS(PostgreSQL) Locally or to Amazon S3 bucket

An open-source CLI tool for backing up RDS(PostgreSQL) Locally or to Amazon S3 bucket

1 Oct 30, 2021
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
Python CLI for accessing CSCI320 PDM Database

p320_14 Python CLI for accessing CSCI320 PDM Database Authors: Aidan Mellin Dan Skigen Jacob Auger Kyle Baptiste Before running the application for th

Aidan Mellin 1 Nov 23, 2021