Package: advent-cli
🎄 advent-cliadvent-cliis a command-line tool for interacting withAdvent 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.Installationpip install advent-cliSetupBefore 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 theAdvent of Code websiteand grab the cookie namedsessionfrom your browser's inspect element tool. Store it in an environment variable on your machine namedADVENT_SESSION_COOKIE. A fresh session cookie is good for about a month, after which you'll need to repeat these steps.A full list of configuration options can be foundhere.Usageadvent-cli can be invoked using theadventcommand, orpython -m advent_cli.Download a question$ advent get YYYY/DDThis will create the directoryYYYY/DD(e.g.2021/01) inside the current working directory. Inside, you'll find part 1 of the puzzle prompt inprompt.md, your puzzle input ininput.txt, and a generated solution template insolution.py. More about thathere.Test a solution$ advent test YYYY/DDThis will run the solution file in the directoryYYYY/DDand print the output without actually submitting. Use this to debug or check for correctness. Optional flags:-e,--example: Test the solution usingexample_input.txt. This is an empty file that gets created when you runadvent getwhere 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 thansolution.py(e.g.-f solution2to runsolution2.py). This will assume you already have a working solution insolution.pyand 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/DDThis will run the solution file in the directoryYYYY/DDand 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 toprompt.md. Run again after implementing part 2 to submit part 2. Optional flags:-f,--solution-file: Submit using a solution file other thansolution.py(e.g.-f solution2to runsolution2.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 yearYYYYand output the table found onadventofcode.com/{YYYY}/leaderboard/selfwith your time, rank, and score for each day and part. If year is not specified, defaults to the current year.Check private leaderboards$ advent stats [YYYY] --privateThis will print out each of the private leaderboards given inADVENT_PRIV_BOARDS. Also works with-p.Countdown to puzzle unlock$ advent countdown YYYY/DDDisplays a countdown until the given puzzle unlocks. Can be chained withgetto auto-download files once the countdown finishes.Solution structureadvent-cli expects the following directory structure (example):2020/
 └─ 01/
     └─ example_input.txt
     └─ input.txt
     └─ prompt.md
     └─ solution.py
     └─ [alternate solution files]
 └─ 02/
     └─ ...
 └─ ...
2021/
 └─ 01/
     └─ ...
 └─ ...Thesolution.pyfile will look like this when first generated:## advent of code {year}## https://adventofcode.com/{year}## day {day}defparse_input(lines):passdefpart1(data):passdefpart2(data):passWhen the solution is run, the input will be read frominput.txtand automatically passed toparse_inputaslines, an array of strings where each string is a line from the input with newline characters removed. You should implementparse_inputto return your parsed input or inputs, which will then be passed topart1andpart2. Ifparse_inputreturns a tuple,part1andpart2will be expecting multiple parameters that map to those returned values. The parameter names can be changed to your liking. The only constraint is thatpart1andpart2must have the same number of parameters.Ifpart2is left unmodified or otherwise returnsNone, it will be considered unsolved andpart1will be run and submitted. If both functions are implemented,part2will be submitted.ConfigurationThe following environment variables can be set to change the default config:VariableFunctionADVENT_SESSION_COOKIEAdvent of Code session cookie for authentication.(required)ADVENT_PRIV_BOARDSComma-separated list of private leaderboard IDs.ADVENT_DISABLE_TERMCOLORSet to1to permanently disable coloring terminal output.ADVENT_MARKDOWN_EMMethod for converting<em>tags inside code blocks. See below for context and options.ADVENT_MARKDOWN_EMoptionsBy default,<em>emphasized text</em>inside code blocks will be converted to markdown format, i.e.*emphasized text*, but with AoC puzzle prompts this can often mess up the formatting. This option can be set to a couple of different things to change this behavior:ValueBehavioribPreserve the<pre><code>tags for code blocks rather than convert them to markdown format and render<em>tags as<i><b>. This can make rendered markdown more readable, although it makes the plaintext less readable if you aren't rendering the markdown.markSame as above, but replace<em>tags with<mark>. This maks the emphasis even more clear than<i><b>, but not all markdown renderers support it.noneIgnore<em>tags and do nothing with their contents. This will preserve plaintext formatting but also hinder the usefulness of the emphasis.defaultDefault behavior (convert<em>to*).ChangelogSeeReleases.CreditsThis started out as a simple script which was inspired byHazelandhaskal.Licenseadvent-cli is distributed under the GNUGPL-3.0 License.