req_aoc.mov
Elixir Req plugin to download Advent of Code input.
The easiest way to use Req is with Mix.install/2
(requires Elixir v1.12+):
Mix.install([
{:req_aoc, github: "mcrumm/req_aoc", ref: "9f1371b"}
])
System.fetch_env!("AOC_SESSION") |> ReqAOC.fetch!({2022, 01})
# ==> "..."
If you want to use ReqAOC in a Mix project, you can add the above dependency to your mix.exs
.
You can also attach ReqAOC to an existing Req.Request
:
req = Req.new() |> ReqAOC.attach()
req |> Req.get!(aoc: {2022, 01, "my-session-id-from-dev-tools"})
# ==> %Req.Response{body: "..."}
In Livebook you can store your session token as an app secret so you
can reuse it across multiple sessions and multiple notebooks. For example, if you create a secret
named AOC_SESSION
, then you can use the following code snippet to fetch your AoC input:
System.fetch_env!("LB_AOC_SESSION") |> ReqAOC.fetch!({2022, 01})
Puzzle inputs differ by user. For this reason, you can't get your data with an unauthenticated request. Here's how to get your session cookie for ReqAOC to use:
- Log in on Advent of Code via any available provider.
- Open your browser's developer console (e.g. right click --> Inspect) and navigate to the Network tab.
- GET any input page, for example https://adventofcode.com/2022/day/1/input, and search in the request headers.
- It's a long hex string. You want the part that comes after
Cookie: session=
. Save that to a system environment variable or a Livebook app secret calledAOC_SESSION
.