Skip to content
/ req_aoc Public

Elixir Req plugin to download Advent of Code input

Notifications You must be signed in to change notification settings

mcrumm/req_aoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReqAOC

req_aoc.mov

Run in Livebook

Elixir Req plugin to download Advent of Code input.

CI

Usage

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: "..."}

Livebook

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})

How to get your session cookie

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 called AOC_SESSION.

Finding your session token

About

Elixir Req plugin to download Advent of Code input

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages