Add code to fetch input from AoC.
This commit is contained in:
parent
a8363ae168
commit
48ba4e1577
15
src/advent/input.cr
Normal file
15
src/advent/input.cr
Normal file
|
@ -0,0 +1,15 @@
|
|||
require "http/client"
|
||||
require "uri"
|
||||
|
||||
def input(year, day)
|
||||
filename = "year#{year}day#{day}.txt.cache"
|
||||
return File.read(filename) if File.exists? filename
|
||||
HTTP::Client.new(URI.parse("https://adventofcode.com")) do |client|
|
||||
client.before_request do |request|
|
||||
request.cookies["session"] = ENV["AOC_SESSION"]
|
||||
end
|
||||
input = client.get("/#{year}/day/#{day}/input").body.to_s
|
||||
File.write(filename, input)
|
||||
return input
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user