Package: advent-of-code-data
Speedhackers, get your puzzle data with a single import statement:fromaocdimportdataIf that sounds too magical, use a simple function call to return your data in a string:>>>fromaocdimportget_data>>>get_data(day=24,year=2015)'1\n2\n3\n7\n11\n13\n17\n19\n23\n31...If you’d just like to print or keep your own raw input files, there’s a script for that:aocd>input.txt# saves today's dataaocd132018>day13.txt# save some other day's dataNote thataocdwill cache puzzle inputs and answers (including incorrect guesses) clientside, to save unnecessary requests to the server.New in version 2.0.0:Get the example data (and corresponding answers). From2022 day 5there was:$aocd20225--example---Day5:SupplyStacks---https://adventofcode.com/2022/day/5-------------------------------Exampledata1/1-------------------------------[D][N][C][Z][M][P]123move1from2to1move3from1to3move2from2to1move1from1to2--------------------------------------------------------------------------------answer_a:CMZanswer_b:MCD--------------------------------------------------------------------------------How does scraping the examples work? Checkaocd-example-parserfor the gory details.QuickstartInstall with pippipinstalladvent-of-code-dataIf you want to use this within a Jupyter notebook, there are some extra deps:pipinstall'advent-of-code-data[nb]'Puzzle inputs differ by user.So export your session ID, for example:exportAOC_SESSION=cafef00db01dfaceba5eba11deadbeefNote:Windows users should usesetinstead ofexporthere.The session ID is a cookie which is set when you login to AoC.  You can find it
with your browser inspector.  If you’re hacking on AoC at all you probably already
know these kind of tricks, but if you need help with that part then you canlook here.Note:If you don’t like the env var, you could also keep your token(s) in files.
By default the location is~/.config/aocd/token. Set theAOCD_DIRenvironment
variable to some existing directory if you wish to use another location to store token(s).New in version 0.9.0.There’s a utility scriptaocd-tokenwhich attempts to
find session tokens from your browser’s cookie storage. This feature is experimental
and requires you to additionally install the packagebrowser-cookie3. Only Chrome
and Firefox browsers are currently supported. On macOS, you may get an authentication
dialog requesting permission, since Python is attempting to read browser storage files.
This is expected, the scriptisactually scraping those private files to access AoC
session token(s).If this utility script was able to locate your token, you can save it to file with:$aocd-token>~/.config/aocd/tokenAutomated submissionNew in version 0.4.0.Basic use:fromaocdimportsubmitsubmit(my_answer,part="a",day=25,year=2017)Note that the same filename introspection of year/day also works for automated
submission. There’s also introspection of the “level”, i.e. part a or part b,
aocd can automatically determine if you have already completed part a or not
and submit your answer for the correct part accordingly. In this case, just use:fromaocdimportsubmitsubmit(my_answer)The response message from AoC will be printed in the terminal. If you gave
the right answer, then the puzzle will be refreshed in your web browser
(so you can read the instructions for the next part, for example).Proceed with caution!If you submit wrong guesses, your userWILLget rate-limited by Eric, so don’t call submit until you’re fairly confident
you have a correct answer!New in version 2.0.0: Prevent submission of an answer when it is certain the value
is incorrect. For example, if the server previously told you that your answer “1234”
was too high, then aocd will remember this info and prevent you from subsequently
submitting an even higher value such as “1300”.ModelsNew in version 0.8.0.There are classesUserandPuzzlefound in the submoduleaocd.models.
Input data is via regular attribute access. Example usage:>>>fromaocd.modelsimportPuzzle>>>puzzle=Puzzle(year=2017,day=20)>>>puzzle<Puzzle(2017,20)at0x107322978-ParticleSwarm>>>>puzzle.input_data'p=<-1027,-979,-188>, v=<7,60,66>, a=<9,1,-7>\np=<-1846,-1539,-1147>, v=<88,145,67>, a=<6,-5,2> ...Submitting answers is also by regular attribute access. Any incorrect answers you submitted are remembered, and aocd will prevent you from attempting to submit the same incorrect value twice:>>>puzzle.answer_a=299That's not the right answer; your answer is too high. If you'restuck,therearesomegeneraltipsontheaboutpage,oryoucanaskforhintsonthesubreddit.Pleasewaitoneminutebeforetryingagain.(Youguessed299.)[ReturntoDay20]>>>puzzle.answer_a=299aocdwillnotsubmitthatansweragain.You've previously guessed 299 and the server responded:That's not the right answer; your answer is too high. If you'restuck,therearesomegeneraltipsontheaboutpage,oryoucanaskforhintsonthesubreddit.Pleasewaitoneminutebeforetryingagain.(Youguessed299.)[ReturntoDay20]Your own solutions can be executed by writing and using anentry-pointinto your code, registered in the group"adventofcode.user". Your entry-point should resolve to a callable, and it will be called with three keyword arguments:year,day, anddata. For example,my entry-point is called “wim”and running againstmy code(afterpip installadvent-of-code-wim) would be like this:>>>puzzle=Puzzle(year=2018,day=10)>>>puzzle.solve_for("wim")('XLZAKBGZ','10656')If you’ve never written a plugin before, seehttps://entrypoints.readthedocs.io/for more info about plugin systems based on Python entry-points.Verify your code against multiple different inputsNew in version 0.8.0.Ever tried running your code against other people’s inputs? AoC is full of tricky edge cases. You may find that sometimes you’re only getting the right answer by luck, and your code will fail on some other dataset. Using aocd, you can collect a few different auth tokens for each of your accounts (github/google/reddit/twitter) and verify your answers across multiple datasets.To see an example of how to setup the entry-point for your code, look atadvent-of-code-samplefor some inspiration. After dumping a bunch of session tokens into~/.config/aocd/tokens.jsonyou could do something like this by running theaocconsole script:As you can see above, I actually had incorrect code for2017 Day 20: Particle Swarm, but thatbugonly showed up for the google token’s dataset. Whoops. Also, it looks like my algorithm for2017 Day 13: Packet Scannerswas kinda garbage. Too slow. According toAoC FAQ:every problem has a solution that completes in at most 15 seconds on ten-year-old hardwareBy the way, theaocrunner will kill your code if it takes more than 60 seconds, you can increase/decrease this by passing a command-line option, e.g.--timeout=120.New in version 1.1.0:Added option--quietto suppress any output from plugins so it doesn’t mess up theaocrunner’s display.New in version 2.0.0:You can verify your code against the example input data and answers, scraped from puzzle pages where available, usingaoc--example. This will pass the sample input data into your solver instead of passing the full user input data.How does this library work?It will automatically get today’s data at import time, if used within the
interactive interpreter.  Otherwise, the date is found by introspection of the
path and file name from whichaocdmodule was imported.This means your filenames should be something sensible. The examples below
should all parse correctly, because they have digits in the path that are
unambiguously recognisable as AoC years (2015+) or days (1-25).q03.py
xmas_problem_2016_25b_dawg.py
~/src/aoc/2015/p8.pyA filename likeproblem_one.pywill not work, so don’t do that.  If
you don’t like weird frame hacks, just use theaocd.get_data()function
instead and have a nice day!Cache invalidation?aocdsaves puzzle inputs, answers, prose, and your bad guesses to avoid hitting
the AoC servers any more often than strictly necessary (this also speeds things up).
All data is persisted in plain text files under~/.config/aocd. To remove any
caches, you may simply delete whatever files you want under that directory tree.
If you’d prefer to use a different path, then export anAOCD_DIRenvironment
variable with the desired location.New in version 1.1.0:By default, your token files are also stored under~/.config/aocd.
If you want the token(s) and cached inputs/answers to exist in separate locations, you can set
the environment variableAOCD_CONFIG_DIRto specify a different location for the token(s).