2022-07-12 20:39:50 +00:00
|
|
|
#!/bin/env ruby
|
|
|
|
require 'optparse'
|
|
|
|
require 'HTTParty'
|
|
|
|
|
2022-07-12 21:06:42 +00:00
|
|
|
options = {}
|
2022-07-12 20:39:50 +00:00
|
|
|
OptionParser.new do |opts|
|
2022-07-12 21:06:42 +00:00
|
|
|
opts.banner = 'aocinit.rb --help'
|
|
|
|
opts.on('-y', '--year year', 'AoC year') do |year|
|
|
|
|
options[:year] = year
|
|
|
|
end
|
|
|
|
opts.on('-d', '--day day', 'AoC day') do |day|
|
|
|
|
options[:day] = day
|
|
|
|
end
|
|
|
|
opts.on('-c', '--cookie-file cookie', 'File containing your AoC cookie') do |cookie|
|
|
|
|
options[:cookie] = cookie
|
|
|
|
end
|
2022-07-12 20:39:50 +00:00
|
|
|
end.parse!
|
|
|
|
|
|
|
|
url = "https://adventofcode.com/#{options[:year]}/day/#{options[:day]}/input"
|
2022-07-12 21:06:42 +00:00
|
|
|
options[:day] = '0' + options[:day] if options[:day].to_i < 10
|
2022-07-12 20:39:50 +00:00
|
|
|
newdir = "./day#{options[:day]}"
|
|
|
|
cookie = File.read("./#{options[:cookie]}")
|
2022-07-12 21:06:42 +00:00
|
|
|
@options = { headers: { 'Cookie' => "session=#{cookie}" } }
|
2022-07-12 20:39:50 +00:00
|
|
|
input = HTTParty.get(url, @options)
|
|
|
|
|
2022-07-12 21:06:42 +00:00
|
|
|
abort 'Day already initiated.' if Dir.exist?(newdir)
|
2022-07-12 20:39:50 +00:00
|
|
|
Dir.mkdir(newdir)
|
|
|
|
Dir.chdir(newdir)
|
|
|
|
File.write('./input', input)
|
2022-07-12 21:06:42 +00:00
|
|
|
File.write('./solution.rb', '#!/bin/env ruby')
|