Skip to content

Commit

Permalink
fix fetch scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin committed Jan 12, 2025
1 parent a7d0db8 commit 3f645a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
16 changes: 2 additions & 14 deletions fetch_input
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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
year = ARGV[2] || (Time.now.year - (Time.now.month < 12 ? 1 : 0)).to_s

headers = {
"Host": "adventofcode.com",
Expand All @@ -26,20 +26,8 @@ headers = {
"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)
raise response unless response.code == 200
puts response.body

5 changes: 3 additions & 2 deletions fetch_puzzle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ 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
# query previous year puzzle if we are not in december yet
year = ARGV[2] || (Time.now.year - (Time.now.month < 12 ? 1 : 0)).to_s

headers = {
"Host": "adventofcode.com",
Expand All @@ -23,12 +24,12 @@ headers = {
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
"Priority": "u=0, i",
"TE": "trailers"
}

# attempt to read puzzle
url = "https://adventofcode.com/#{year}/day/#{day}"
response = HTTParty.get(url, headers: headers)
raise response unless response.code == 200
begin
stdin, stdout, stderr, wait_thr = Open3.popen3("pandoc --from html --to markdown_strict")
stdin.write response.body
Expand Down
2 changes: 1 addition & 1 deletion newday
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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
year = ARGV[2] || (Time.now.year - (Time.now.month < 12 ? 1 : 0)).to_s

dayname = "day" + day.to_s.rjust(2, '0')

Expand Down

0 comments on commit 3f645a1

Please sign in to comment.