-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_input
executable file
·45 lines (40 loc) · 1.3 KB
/
fetch_input
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env ruby
require 'open3'
require 'httparty'
raise "Missing day" unless ARGV[0] =~ /[0-9]+/
day = ARGV[0]
raise "Missing session" unless ARGV[1] =~ /[a-z0-9]+/
session = ARGV[1]
year = ARGV[2] || Time.now.year.to_s
headers = {
"Host": "adventofcode.com",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Referer": "https://adventofcode.com/",
"Connection": "keep-alive",
"Cookie": "session=#{session}",
"Upgrade-Insecure-Requests": "1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
"Priority": "u=0, i",
"TE": "trailers"
}
if false
# attempt to read puzzle
url = "https://adventofcode.com/#{year}/day/#{day}"
response = HTTParty.get(url, headers: headers)
begin
stdin, stdout, stderr, wait_thr = Open3.popen3("pandoc --from html --to markdown_strict")
stdin.write response.body
stdin.close
# Read and print output from the Ruby file
puts stdout.read
end
end
url = "https://adventofcode.com/#{year}/day/#{day}/input"
response = HTTParty.get(url, headers: headers)
puts response.body