Package: advoco
AdvocoAdvent of Code helper library - why not??
Dear future contributor traipsing through history,
this was when this was a private repo that me and a buddy were collaborating on.
If this README does not look more polished in the current version, hunt me down
and slap me.InstallpoetryinstallI'm still working actively so do this often.tl;drDo this once a year:advocogenerate-yearThen grab your session cookie from AoC using browser tools and add it to the
environment asAOC_TOKEN. Put it in your.bashrcand never think about it
again (until next year). The session lasts like a month so you shouldn't have to
do this that often.Then, every day,from the directory created with the generate-year command:advocogenerate-d<dayyouwanttogenerate>or if it's after midnight, AoC time (Eastern):advocogenerateIn the generated script file, you'll find a function for part1 and part2 of the
daily AoC puzzle. You'll also find atransformfunction. This function will act
on eachlineof the input. For instance, input always comes in as a string, so
if you want your puzzle input to be a list of ints, do this:deftransform(line):returnint(line)The last thing you'll find in the script is the call toadvoco.do(). It starts
out withsample=Trueand will therefore attempt to parse the sample input Eric
uses on the webpage of the daily puzzle. It'll throw an error and give you advice
if it can't find sample input. When you're ready to try your solutions on your
real input, remove the sample argument.ExplanationsSome context...WTF isdodoing?When you calldo(), advoco inspects the call stack for the file that called it.
It looks through that file (as a module, usinggetattr) for a few things:Atransformfunc. If it doesn't find one, the default one is basicallylambda x: return xSome part functions, i.e.part1,part2It gets the raw input for the puzzle you're working on (more on that below), runs
that through whatever transform it's using, then passes it as the arg to thepartfunctions it found in your script file.Finally, it gets the result of yourpartfunction and prints it. It does not yet
attempt to submit the answer for you, and it may not do that ever (not sure yet).WHATYEAR(AND DAY) IS IT???Advoco needs to figure out which puzzle input to go get, both the puzzle year and
the puzzle day. To determine this - really in all instances where advoco needs to
figure out a year and/or day - the following order is honored:Anything explicitly passed. If you pass adayoryeararg todo, that is
what advoco is going to work with. End of discussion. Explicit declaration trumps
all.The calling context. Where isdobeing called from? Where is a cli command
being invoked? Ifdois being called from a python file, and that file name contains
digits, those digits are assumed to represent the day you want to work on. Further,
if that python file lives in a directory whose name contains the regexr"20\d{2}",
then that regex match is assumed to be the year. For cli invocations, the folder
== year convention holds, but the day is never inferred from calling context.The current day and year, in the AoC timezone (America/New_York).NotesThis still assumes that we're gonna be working with a list of lines as our input.
I haven't yet figured out the best way to handle the case where you want the whole
damn input string as one blob. Good ideas are welcome here.Any input fetched from the AoC site is cached in~/.cache/advocoto not pester
the site. The inputs, as far as I can tell, have never and will never change, so
there's no cache expiry mechanism.Thegenerate-yearcommand creates a top level folder called_localonly_2022.
This is just so you can AoC from within the advoco repo without git stressing out.
When it's ready for prime time, I'll change it to make a2022directory.ContributingBug reports are awesome but if you see something and you know how to fix it, by
all means! Just make a new branch and open a PR. Hell, just push directly to main
if you're super confident.