fixed formatting

main
s00ner 2022-07-12 17:06:42 -04:00
parent 3f01d5d654
commit 667edb6369
1 changed files with 15 additions and 15 deletions

View File

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