add get_input task
call with `mix get_input <year> <day>` and it will write to `input/<year>_<day>.txt`
This commit is contained in:
parent
0d4599d1ba
commit
5f3ac1eb76
1 changed files with 23 additions and 0 deletions
23
lib/get_input.ex
Normal file
23
lib/get_input.ex
Normal file
|
@ -0,0 +1,23 @@
|
|||
defmodule Mix.Tasks.GetInput do
|
||||
defp get_session() do
|
||||
{_, content} = File.read("./.session")
|
||||
content |> String.trim()
|
||||
end
|
||||
|
||||
defp get_request_headers() do
|
||||
[Cookie: "session=#{get_session()}"]
|
||||
end
|
||||
|
||||
def run(args) do
|
||||
[year, day] = args
|
||||
write_file = &File.write("./input/#{year}_#{day}.txt", &1)
|
||||
HTTPoison.start
|
||||
HTTPoison.get!(
|
||||
"https://adventofcode.com/#{year}/day/#{day}/input",
|
||||
get_request_headers()
|
||||
)
|
||||
|> Map.get(:body)
|
||||
|> then(fn i -> IO.puts(i); i end)
|
||||
|> write_file.()
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue