advent_of_code_generator 0.0.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +8 -0
- data/exe/aoc +6 -0
- data/lib/advent_of_code_generator/generate_day.rb +64 -0
- data/lib/advent_of_code_generator/templates/empty_day.tt +15 -0
- data/lib/advent_of_code_generator/utils/error.rb +20 -0
- data/lib/advent_of_code_generator/utils/parser.rb +19 -0
- data/lib/advent_of_code_generator/utils/version.rb +5 -0
- data/lib/advent_of_code_generator/utils.rb +5 -0
- data/lib/advent_of_code_generator.rb +23 -25
- metadata +37 -8
- data/lib/advent_of_code_generator/generate.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7edb73d2264ff39da5a3eccb4b3cef4766f920bb5f8c27d798585c6ce2e945ed
|
4
|
+
data.tar.gz: '059f62d54f1049df523518674d56dcb7db5ab6f96dd5309da149b4a19e203b95'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dffc5cd6a6c0aa711532ce643ede0f5fd8dc2ab0e30773e41244c6e722989fb6f16c212b39b870f2bd91de64af320e4b5b31b08ae1062111e5972e36b1c32065
|
7
|
+
data.tar.gz: 4ac450d516794e5bfd80eecaaf4a0e3196f578941e85eb9e69ee82626f0d8c5c43cf2889a4f5fa8118ab25f4a1e98eb05d1ed1c6c661243b5203110930332054
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in advent_of_code_generator.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
gem "rubocop", "~> 1.21"
|
10
|
+
gem 'thor', '~> 1.2', '>= 1.2.1'
|
11
|
+
gem "pry"
|
12
|
+
gem 'rest-client', '~> 2.1'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
advent_of_code_generator (0.1.0)
|
5
|
+
thor (~> 1.2, >= 1.2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
coderay (1.1.3)
|
12
|
+
domain_name (0.5.20190701)
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
14
|
+
http-accept (1.7.0)
|
15
|
+
http-cookie (1.0.5)
|
16
|
+
domain_name (~> 0.5)
|
17
|
+
json (2.6.2)
|
18
|
+
method_source (1.0.0)
|
19
|
+
mime-types (3.4.1)
|
20
|
+
mime-types-data (~> 3.2015)
|
21
|
+
mime-types-data (3.2022.0105)
|
22
|
+
netrc (0.11.0)
|
23
|
+
parallel (1.22.1)
|
24
|
+
parser (3.1.3.0)
|
25
|
+
ast (~> 2.4.1)
|
26
|
+
pry (0.14.1)
|
27
|
+
coderay (~> 1.1)
|
28
|
+
method_source (~> 1.0)
|
29
|
+
rainbow (3.1.1)
|
30
|
+
rake (13.0.6)
|
31
|
+
regexp_parser (2.6.1)
|
32
|
+
rest-client (2.1.0)
|
33
|
+
http-accept (>= 1.7.0, < 2.0)
|
34
|
+
http-cookie (>= 1.0.2, < 2.0)
|
35
|
+
mime-types (>= 1.16, < 4.0)
|
36
|
+
netrc (~> 0.8)
|
37
|
+
rexml (3.2.5)
|
38
|
+
rubocop (1.39.0)
|
39
|
+
json (~> 2.3)
|
40
|
+
parallel (~> 1.10)
|
41
|
+
parser (>= 3.1.2.1)
|
42
|
+
rainbow (>= 2.2.2, < 4.0)
|
43
|
+
regexp_parser (>= 1.8, < 3.0)
|
44
|
+
rexml (>= 3.2.5, < 4.0)
|
45
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
46
|
+
ruby-progressbar (~> 1.7)
|
47
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
48
|
+
rubocop-ast (1.24.0)
|
49
|
+
parser (>= 3.1.1.0)
|
50
|
+
ruby-progressbar (1.11.0)
|
51
|
+
thor (1.2.1)
|
52
|
+
unf (0.1.4)
|
53
|
+
unf_ext
|
54
|
+
unf_ext (0.0.8.2)
|
55
|
+
unicode-display_width (2.3.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
x86_64-linux
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
advent_of_code_generator!
|
62
|
+
pry
|
63
|
+
rake (~> 13.0)
|
64
|
+
rest-client (~> 2.1)
|
65
|
+
rubocop (~> 1.21)
|
66
|
+
thor (~> 1.2, >= 1.2.1)
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
2.3.18
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Tyflomate
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# AdventOfCodeGenerator
|
2
|
+
|
3
|
+
A custom gem that allows you to generate the necessary files to solve [Advent of Code](https://advent-of-code.com) days in Ruby !
|
4
|
+
|
5
|
+
This project is based on [advent_of_code_cli](https://github.com/egiurleo/advent_of_code_cli). Pretty much the same
|
6
|
+
usage but I wanted to make my own because why not ! Go check it out 👌
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
You can add this line to your Gemfile:
|
11
|
+
|
12
|
+
$ gem "advent_of_code_generator"
|
13
|
+
|
14
|
+
Then run bundle install and your up to go !
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
### Generate
|
19
|
+
|
20
|
+
For this gem to work, we need to use you Advent of code session cookie in order to fetch your input. You can find
|
21
|
+
it in the cookies of https://adventofcode.com/2022/day/DAY/input. Add it to you environment variables as:
|
22
|
+
|
23
|
+
```
|
24
|
+
export AOC_COOKIE=COOKIE
|
25
|
+
```
|
26
|
+
|
27
|
+
To generate a day of the current year, run:
|
28
|
+
|
29
|
+
$ bundle exec aoc generate --day DAY
|
30
|
+
|
31
|
+
This will create a directory for the day DAY with the ruby file class to solve the puzzle and the input file.
|
32
|
+
|
33
|
+
### Solve
|
34
|
+
|
35
|
+
Incomming command
|
36
|
+
|
37
|
+
### Publish
|
38
|
+
|
39
|
+
Incomming command
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on this GitHub repository.
|
data/Rakefile
ADDED
data/exe/aoc
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
module AdventOfCodeGenerator
|
6
|
+
class GenerateDay < Thor::Group
|
7
|
+
include Thor::Actions
|
8
|
+
|
9
|
+
class_option :day, :type => :numeric
|
10
|
+
class_option :year, :type => :numeric
|
11
|
+
|
12
|
+
def self.source_root
|
13
|
+
File.dirname(__FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_day_directory
|
17
|
+
unless Dir.exist?(day_name)
|
18
|
+
say "Creating day #{day} directory", :green
|
19
|
+
Dir.mkdir(day_name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_solution_file
|
24
|
+
say "Creating day #{day} solution file", :green
|
25
|
+
template('templates/empty_day.tt', "#{day_name}/day#{day_name}.rb")
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_input_file
|
29
|
+
say "Creating day #{day} input file", :green
|
30
|
+
create_file "#{day_name}/input.txt", fetch_input
|
31
|
+
end
|
32
|
+
|
33
|
+
def prints_done
|
34
|
+
say 'Generation done, enjoy !', :blue
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def fetch_input
|
40
|
+
binding.pry
|
41
|
+
RestClient.get(
|
42
|
+
"https://adventofcode.com/#{year}/day/#{day}/input",
|
43
|
+
cookies: { session: ENV.fetch('AOC_COOKIE', '') },
|
44
|
+
'User-Agent' => "github.com/Tyflomate/advent_of_code_generator by florian@tymate.com"
|
45
|
+
).body
|
46
|
+
rescue RestClient::BadRequest, RestClient::ExceptionWithResponse => e
|
47
|
+
e.response
|
48
|
+
end
|
49
|
+
|
50
|
+
def day
|
51
|
+
@day ||= options[:day]
|
52
|
+
end
|
53
|
+
|
54
|
+
def day_name
|
55
|
+
return day.to_s if day > 9
|
56
|
+
|
57
|
+
"0#{day}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def year
|
61
|
+
@year ||= options[:year]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Day<%= day_name %>
|
4
|
+
def initialize
|
5
|
+
@input = File.readlines('./<%= day_name %>/input.txt')
|
6
|
+
end
|
7
|
+
|
8
|
+
def part1
|
9
|
+
# TODO: Write your solution here
|
10
|
+
end
|
11
|
+
|
12
|
+
def part2
|
13
|
+
# TODO: Write your solution here
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module AdventOfCodeGenerator
|
3
|
+
class Error < StandardError
|
4
|
+
def message
|
5
|
+
raise NotImplementedError
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class InvalidDayError < Error
|
10
|
+
def message
|
11
|
+
"Please use an integer between 1 and 25 as day argument."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class InvalidYearError < Error
|
16
|
+
def message
|
17
|
+
"Please insert a valid year between the first iteration of 2015 and current year."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AdventOfCodeGenerator
|
4
|
+
module Parser
|
5
|
+
def parse_day(day)
|
6
|
+
return day if day > 0 && day < 26
|
7
|
+
|
8
|
+
raise InvalidDayError
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_year(year)
|
12
|
+
current_year = Time.now.year
|
13
|
+
return current_year unless year
|
14
|
+
return year if year <= current_year && year > 2014
|
15
|
+
|
16
|
+
raise InvalidYearError
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,37 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "thor"
|
4
|
+
require "pry"
|
5
|
+
require_relative "advent_of_code_generator/utils"
|
6
|
+
require_relative "advent_of_code_generator/generate_day"
|
4
7
|
|
5
|
-
|
6
|
-
|
8
|
+
module AdventOfCodeGenerator
|
9
|
+
class Error < StandardError; end
|
7
10
|
|
8
|
-
|
11
|
+
class App < Thor
|
12
|
+
include Thor::Actions
|
13
|
+
include AdventOfCodeGenerator::Parser
|
9
14
|
|
10
|
-
|
11
|
-
method_option :year => :integer, :aliases => "-y"
|
12
|
-
desc "generate", "generate files for a day"
|
13
|
-
def generate
|
14
|
-
day = parse_day(options[:day])
|
15
|
-
year = parse_year(options[:year])
|
16
|
-
puts "generating day #{day} of year #{year}"
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
15
|
+
map "-g" => :generate
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
option :day, :type => :numeric, :required => true, :aliases => "-d"
|
18
|
+
option :year, :type => :numeric, :aliases => "-y"
|
19
|
+
desc "generate", "generate files for a day"
|
20
|
+
def generate
|
21
|
+
day = parse_day(options[:day])
|
22
|
+
year = parse_year(options[:year])
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
invoke 'generateDay', [], :day => day, :year => year
|
25
|
+
rescue AdventOfCodeGenerator::Error => e
|
26
|
+
say e.message, :red
|
27
|
+
end
|
31
28
|
|
32
|
-
|
33
|
-
return parsed_year if parsed_year <= current_year && parsed_year > 2014
|
29
|
+
register(AdventOfCodeGenerator::GenerateDay, "generateDay", "generateDay", "Generate days files")
|
34
30
|
|
35
|
-
|
31
|
+
def self.exit_on_failure?
|
32
|
+
true
|
33
|
+
end
|
36
34
|
end
|
37
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: advent_of_code_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Lecointe
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -30,18 +30,47 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.2.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rest-client
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.1'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.1'
|
33
47
|
description: Generate input and startup class for advent of code days
|
34
48
|
email: florian@tymate.com
|
35
|
-
executables:
|
49
|
+
executables:
|
50
|
+
- aoc
|
36
51
|
extensions: []
|
37
52
|
extra_rdoc_files: []
|
38
53
|
files:
|
54
|
+
- ".rubocop.yml"
|
55
|
+
- Gemfile
|
56
|
+
- Gemfile.lock
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- exe/aoc
|
39
61
|
- lib/advent_of_code_generator.rb
|
40
|
-
- lib/advent_of_code_generator/
|
41
|
-
|
62
|
+
- lib/advent_of_code_generator/generate_day.rb
|
63
|
+
- lib/advent_of_code_generator/templates/empty_day.tt
|
64
|
+
- lib/advent_of_code_generator/utils.rb
|
65
|
+
- lib/advent_of_code_generator/utils/error.rb
|
66
|
+
- lib/advent_of_code_generator/utils/parser.rb
|
67
|
+
- lib/advent_of_code_generator/utils/version.rb
|
68
|
+
homepage: https://github.com/Tyflomate/advent_of_code_generator
|
42
69
|
licenses:
|
43
70
|
- MIT
|
44
|
-
metadata:
|
71
|
+
metadata:
|
72
|
+
homepage_uri: https://github.com/Tyflomate/advent_of_code_generator
|
73
|
+
source_code_uri: https://github.com/Tyflomate/advent_of_code_generator
|
45
74
|
post_install_message:
|
46
75
|
rdoc_options: []
|
47
76
|
require_paths:
|
@@ -50,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
79
|
requirements:
|
51
80
|
- - ">="
|
52
81
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
82
|
+
version: 2.6.0
|
54
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
84
|
requirements:
|
56
85
|
- - ">="
|