updated gitignore and added aocinit

main
s00ner 2022-12-02 10:59:13 -05:00
parent e6808c88bf
commit d12c935f9d
2 changed files with 31 additions and 0 deletions

1
.gitignore vendored
View File

@ -56,3 +56,4 @@ build-iPhoneSimulator/
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
# .rubocop-https?--*
cookie.txt

30
aocinit.rb Normal file
View File

@ -0,0 +1,30 @@
#!/bin/env ruby
require 'optparse'
require 'httparty'
options = {}
OptionParser.new do |opts|
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
end.parse!
url = "https://adventofcode.com/#{options[:year]}/day/#{options[:day]}/input"
options[:day] = '0' + options[:day] if options[:day].to_i < 10
newdir = "./day#{options[:day]}"
cookie = File.read("./#{options[:cookie]}")
@options = { headers: { 'Cookie' => "session=#{cookie}" } }
input = HTTParty.get(url, @options)
abort 'Day already initiated.' if Dir.exist?(newdir)
Dir.mkdir(newdir)
Dir.chdir(newdir)
File.write('./input', input)
File.write('./solution.rb', '#!/bin/env ruby')