๐ŸŽ„ Advent of Code command-line tool.

Related tags

CLI Tools advent-cli
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 cd command that learns - easily navigate directories from the command line

NAME autojump - a faster way to navigate your filesystem DESCRIPTION autojump is a faster way to navigate your filesystem. It works by maintaining a d

William Ting 14.5k Jan 3, 2023
Ros command - Unifying the ROS command line tools

Unifying the ROS command line tools One impairment to ROS 2 adoption is that all

null 37 Dec 15, 2022
A command line tool to query source code from your current Python env

wxc wxc (pronounced "which") allows you to inspect source code in your Python environment from the command line. It is based on the inspect module fro

Clรฉment Robert 13 Nov 8, 2022
A command-line tool to flash python code to Codey Rocky without having to use the online mblock5 IDE.

What? A command-line tool to flash python code to Codey Rocky without having to use the online mblock5 IDE. Description This is a very low-effort proj

null 1 Dec 29, 2021
Command-line tool for looking up colors and palettes.

Colorpedia Colorpedia is a command-line tool for looking up colors, shades and palettes. Supported color models: HEX, RGB, HSL, HSV, CMYK. Requirement

Joohwan Oh 282 Dec 27, 2022
Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network)

Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network)

Phil Wang 4.4k Jan 9, 2023
Free and Open-Source Command Line tool for Text Replacement

Sniplet Free and Open Source Text Replacement Tool Description: Sniplet is a work in progress CLI tool which can do text replacement globally in Linux

Veeraraghavan Narasimhan 13 Nov 28, 2022
PwnWiki command line searching tool & bindings written in Python

pwsearch PwnWiki ๆ•ฐๆฎๅบ“ๆœ็ดขๅ‘ฝไปค่กŒๅทฅๅ…ทใ€‚ ๅฎ‰่ฃ… ๆ‚จๅฏไปฅ็›ดๆŽฅ็”จ pip ๅ‘ฝไปคไปŽ PyPI ๅฎ‰่ฃ… pwsearch๏ผš pip3 install -U pwsearch ๆ‚จไนŸๅฏไปฅ clone ่ฏฅไป“ๅบ“ๅนถ็›ดๆŽฅไปŽๆบ็ ๅฏๅŠจ

PwnWiki 20 Jun 21, 2021
Official AIdea command line tool

AIdea CLI Official AIdea command line tool for https://aidea-web.tw. Installation Make sure you have installed both Python 3 and pip package manager.

AIdea 5 Dec 15, 2021