aocli 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +99 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +30 -0
- data/exe/aocli +6 -0
- data/lib/aocli/advent_of_code/client.rb +72 -0
- data/lib/aocli/advent_of_code.rb +64 -0
- data/lib/aocli/cli.rb +64 -0
- data/lib/aocli/commands/save_cookie.rb +17 -0
- data/lib/aocli/commands/start_day.rb +55 -0
- data/lib/aocli/content/main.rb +34 -0
- data/lib/aocli/cookie_retriever.rb +18 -0
- data/lib/aocli/file_utils.rb +54 -0
- data/lib/aocli/values.rb +7 -0
- data/lib/aocli/version.rb +5 -0
- data/lib/aocli.rb +19 -0
- data/public/aocli-cookie-helper.png +0 -0
- data/sig/aocli.rbs +4 -0
- metadata +212 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c6091e0da2c8e5095487295b5ee075ffa44252864b43630205c28d6e393bc4c
|
4
|
+
data.tar.gz: 8c1b2939b51eecda5d51e83f6c7389dc5d476622897a7f15423ee54b6187d0ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c88d2c4325a7670d4b531c58d394e709727384380c195086efd1fd490e9386c78a09268f295f4ecf5eed91b236c052acb5d38fde08d6848c27d82ac3ad6fc6f5
|
7
|
+
data.tar.gz: 711b283c3b9537fa4cb443120144f7697b45020645123e6f026568b1e72dad8c0092f4195f695058e4adfe0f0163672577748388b07862eb522d3c392cf5e323
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at astley92@hotmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aocli (1.3.0)
|
5
|
+
activesupport (~> 7.0)
|
6
|
+
faraday (~> 2.7)
|
7
|
+
nokogiri (~> 1.13)
|
8
|
+
tty-prompt (~> 0.23.1)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (7.0.4)
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
minitest (>= 5.1)
|
17
|
+
tzinfo (~> 2.0)
|
18
|
+
ast (2.4.2)
|
19
|
+
byebug (11.1.3)
|
20
|
+
concurrent-ruby (1.1.10)
|
21
|
+
diff-lcs (1.5.0)
|
22
|
+
faraday (2.7.1)
|
23
|
+
faraday-net_http (>= 2.0, < 3.1)
|
24
|
+
ruby2_keywords (>= 0.0.4)
|
25
|
+
faraday-net_http (3.0.2)
|
26
|
+
i18n (1.12.0)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
json (2.6.2)
|
29
|
+
minitest (5.16.3)
|
30
|
+
nokogiri (1.13.9-arm64-darwin)
|
31
|
+
racc (~> 1.4)
|
32
|
+
parallel (1.22.1)
|
33
|
+
parser (3.1.3.0)
|
34
|
+
ast (~> 2.4.1)
|
35
|
+
pastel (0.8.0)
|
36
|
+
tty-color (~> 0.5)
|
37
|
+
racc (1.6.0)
|
38
|
+
rainbow (3.1.1)
|
39
|
+
rake (13.0.6)
|
40
|
+
regexp_parser (2.6.1)
|
41
|
+
rexml (3.2.5)
|
42
|
+
rspec (3.12.0)
|
43
|
+
rspec-core (~> 3.12.0)
|
44
|
+
rspec-expectations (~> 3.12.0)
|
45
|
+
rspec-mocks (~> 3.12.0)
|
46
|
+
rspec-core (3.12.0)
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-expectations (3.12.0)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.12.0)
|
51
|
+
rspec-mocks (3.12.0)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.12.0)
|
54
|
+
rspec-support (3.12.0)
|
55
|
+
rubocop (1.39.0)
|
56
|
+
json (~> 2.3)
|
57
|
+
parallel (~> 1.10)
|
58
|
+
parser (>= 3.1.2.1)
|
59
|
+
rainbow (>= 2.2.2, < 4.0)
|
60
|
+
regexp_parser (>= 1.8, < 3.0)
|
61
|
+
rexml (>= 3.2.5, < 4.0)
|
62
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
63
|
+
ruby-progressbar (~> 1.7)
|
64
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
65
|
+
rubocop-ast (1.23.0)
|
66
|
+
parser (>= 3.1.1.0)
|
67
|
+
ruby-progressbar (1.11.0)
|
68
|
+
ruby2_keywords (0.0.5)
|
69
|
+
timecop (0.9.5)
|
70
|
+
tty-color (0.6.0)
|
71
|
+
tty-cursor (0.7.1)
|
72
|
+
tty-prompt (0.23.1)
|
73
|
+
pastel (~> 0.8)
|
74
|
+
tty-reader (~> 0.8)
|
75
|
+
tty-reader (0.9.0)
|
76
|
+
tty-cursor (~> 0.7)
|
77
|
+
tty-screen (~> 0.8)
|
78
|
+
wisper (~> 2.0)
|
79
|
+
tty-screen (0.8.1)
|
80
|
+
tzinfo (2.0.5)
|
81
|
+
concurrent-ruby (~> 1.0)
|
82
|
+
unicode-display_width (2.3.0)
|
83
|
+
vcr (6.1.0)
|
84
|
+
wisper (2.0.1)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
arm64-darwin-21
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
aocli!
|
91
|
+
byebug (~> 11.0)
|
92
|
+
rake (~> 13.0)
|
93
|
+
rspec (~> 3.0)
|
94
|
+
rubocop (~> 1.0)
|
95
|
+
timecop (~> 0.9)
|
96
|
+
vcr (~> 6.1)
|
97
|
+
|
98
|
+
BUNDLED WITH
|
99
|
+
2.3.25
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Blake Astley
|
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,53 @@
|
|
1
|
+
# Aocli
|
2
|
+
|
3
|
+
A simple CLI that helps start any advent of code problem by retrieving the probem decription,your unique inputs and putting together boilerplate code so you can start solving as soon as possible.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem using
|
8
|
+
|
9
|
+
```bash
|
10
|
+
gem install aocli
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Once installed simply run
|
16
|
+
|
17
|
+
```bash
|
18
|
+
aocli
|
19
|
+
```
|
20
|
+
|
21
|
+
You'll need to save your advent of code cookie before you can do anything else, simply select the save cookie option and paste your cookie in when prompted. This will save the cookie in the config file located at `~/aocli_config`.
|
22
|
+
|
23
|
+
## How Do I Get My Advent Of Code Cookie
|
24
|
+
|
25
|
+
Advent of code uses a cookie to authenticate and determine the current user. To find out what your cookie is, simply go to [advent of code](TODO) and login using Github.
|
26
|
+
|
27
|
+
Once that's done
|
28
|
+
|
29
|
+
1. Open up the developer tools
|
30
|
+
1. Find the network tab
|
31
|
+
1. Navigate to any days problem
|
32
|
+
1. find the network entry with the name of the current days problem
|
33
|
+
1. In this network entry, you should find a request header called `cookie`.
|
34
|
+
1. The value of this header is your cookie
|
35
|
+
1. Copy that value, run `aocli`, select save cookie and paste it in when prompted
|
36
|
+
|
37
|
+
For the example shown, I viewed 2018 day 11 and can see the cookie inside the contents of the network tab named `11`
|
38
|
+
|
39
|
+
![cookie-example](/public/aocli-cookie-helper.png)
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
44
|
+
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/astley92/aocli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/astley92/aocli/CODE_OF_CONDUCT.md).
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
require "rubocop/rake_task"
|
8
|
+
RuboCop::RakeTask.new
|
9
|
+
|
10
|
+
task default: %i[spec rubocop]
|
11
|
+
|
12
|
+
task :build do
|
13
|
+
system "gem build aocli.gemspec"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :install => :build do
|
17
|
+
system "gem install aocli-" + Aocli::VERSION + ".gem"
|
18
|
+
end
|
19
|
+
|
20
|
+
task :install_and_run => :install do
|
21
|
+
system "aocli"
|
22
|
+
end
|
23
|
+
|
24
|
+
task :publish => :build do
|
25
|
+
system "gem push aocli-" + Aocli::VERSION + ".gem"
|
26
|
+
end
|
27
|
+
|
28
|
+
task :clean do
|
29
|
+
system "rm *.gem"
|
30
|
+
end
|
data/exe/aocli
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require("faraday")
|
2
|
+
|
3
|
+
module Aocli
|
4
|
+
module AdventOfCode
|
5
|
+
|
6
|
+
Response = Struct.new(:status, :should_retry, :body, keyword_init: true) do
|
7
|
+
def should_retry?
|
8
|
+
self.should_retry
|
9
|
+
end
|
10
|
+
|
11
|
+
def ok?
|
12
|
+
status == 200
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Client
|
17
|
+
attr_reader :conn
|
18
|
+
def initialize
|
19
|
+
@cookie = Aocli::CookieRetriever.call
|
20
|
+
@conn = initialise_conn_object
|
21
|
+
raise(StandardError, "No cookie is set") unless @cookie
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_problem_inputs(year:, day:)
|
25
|
+
res = conn.get("/#{year}/day/#{day}/input")
|
26
|
+
case res.status
|
27
|
+
when 200
|
28
|
+
Response.new(
|
29
|
+
status: res.status,
|
30
|
+
body: res.body,
|
31
|
+
should_retry: false,
|
32
|
+
)
|
33
|
+
else
|
34
|
+
Response.new(
|
35
|
+
status: res.status,
|
36
|
+
body: res.body,
|
37
|
+
should_retry: false,
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_problem_description(year:, day:)
|
43
|
+
res = conn.get("/#{year}/day/#{day}")
|
44
|
+
case res.status
|
45
|
+
when 200
|
46
|
+
Response.new(status: res.status, body: res.body, should_retry: false)
|
47
|
+
when 404
|
48
|
+
Response.new(
|
49
|
+
status: res.status,
|
50
|
+
body: res.body,
|
51
|
+
should_retry: res.body.include?("Please don't repeatedly request this endpoint before it unlocks!"),
|
52
|
+
)
|
53
|
+
else
|
54
|
+
Response.new(
|
55
|
+
status: res.status,
|
56
|
+
body: res.body,
|
57
|
+
should_retry: false,
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def initialise_conn_object
|
65
|
+
Faraday.new(
|
66
|
+
url: "https://adventofcode.com/",
|
67
|
+
headers: {'Cookie' => @cookie },
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require("aocli/advent_of_code/client")
|
2
|
+
|
3
|
+
module Aocli
|
4
|
+
module AdventOfCode
|
5
|
+
MAX_RETRY_COUNT = 5
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def get_problem_description(year:, day:)
|
9
|
+
wait_for_start(year: year, day: day)
|
10
|
+
response = fetch_description(year: year, day: day)
|
11
|
+
extract_text(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_problem_inputs(year:, day:)
|
15
|
+
response = client.get_problem_inputs(year: year, day: day)
|
16
|
+
unless response.ok?
|
17
|
+
raise(StandardError, "unable to fetch input - #{response.inspect}")
|
18
|
+
end
|
19
|
+
|
20
|
+
response.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def client
|
24
|
+
@client ||= Aocli::AdventOfCode::Client.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def wait_for_start(day:, year:)
|
28
|
+
while true
|
29
|
+
current_time = DateTime.now.new_offset("EST")
|
30
|
+
live_time = DateTime.new(year, 12, day, 0, 0, 0, "EST")
|
31
|
+
time_to_wait = ((live_time - current_time) * 24 * 60 * 60).to_i
|
32
|
+
break if time_to_wait < 1
|
33
|
+
|
34
|
+
print("\rWaiting #{time_to_wait} seconds before fetching...".ljust(40, " "))
|
35
|
+
sleep(1)
|
36
|
+
end
|
37
|
+
puts
|
38
|
+
end
|
39
|
+
|
40
|
+
def fetch_description(year:, day:)
|
41
|
+
response = nil
|
42
|
+
attempt_count = 0
|
43
|
+
while attempt_count < MAX_RETRY_COUNT
|
44
|
+
attempt_count += 1
|
45
|
+
print("\rFetching problem and input attempt ##{attempt_count}".ljust(40, " "))
|
46
|
+
response = client.get_problem_description(year: year, day: day)
|
47
|
+
break unless response.should_retry?
|
48
|
+
|
49
|
+
sleep(1)
|
50
|
+
end
|
51
|
+
puts
|
52
|
+
raise(StandardError, "Unable to fetch todays problem: #{response.inspect}") unless response.ok?
|
53
|
+
|
54
|
+
response
|
55
|
+
end
|
56
|
+
|
57
|
+
def extract_text(response)
|
58
|
+
html = Nokogiri::HTML(response.body)
|
59
|
+
article = html.css("article").first
|
60
|
+
article.search("p,h2").each { |element| element.after("\n") }
|
61
|
+
article.text
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/aocli/cli.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
require"byebug"
|
3
|
+
module Aocli
|
4
|
+
class Cli
|
5
|
+
def initialize
|
6
|
+
@options = {cookie: Aocli::CookieRetriever.call}
|
7
|
+
@prompt = TTY::Prompt.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
prompt_for_command
|
12
|
+
get_all_command_options
|
13
|
+
# Aocli::Commands::StartDay
|
14
|
+
# Aocli::Commands::SaveCookie
|
15
|
+
options[:command].constantize.run!(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
attr_accessor :options, :prompt
|
20
|
+
attr_reader :cookie
|
21
|
+
|
22
|
+
def prompt_for_command
|
23
|
+
options[:command] = prompt.select("What would you like to do?", command_options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_all_command_options
|
27
|
+
case options[:command]
|
28
|
+
when "Aocli::Commands::StartDay"
|
29
|
+
set_start_day_options
|
30
|
+
when "Aocli::Commands::SaveCookie"
|
31
|
+
set_save_cookie_options
|
32
|
+
when "Exit"
|
33
|
+
exit
|
34
|
+
else
|
35
|
+
raise NotImplementedError, "Can't handle that command: #{command_klass}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def command_options
|
40
|
+
@command_options ||= [
|
41
|
+
{name: "Save Cookie", value: "Aocli::Commands::SaveCookie"},
|
42
|
+
requires_cookie({name: "Start day", value: "Aocli::Commands::StartDay"}),
|
43
|
+
{name: "Exit", value: "Exit"},
|
44
|
+
]
|
45
|
+
# TODO:
|
46
|
+
# requires_cookie({name: "Remove cookie file", value: "Aocli::Commands::RemoveCookieFile"}),
|
47
|
+
end
|
48
|
+
|
49
|
+
def requires_cookie(hash)
|
50
|
+
hash.merge(options[:cookie] ? {} : {disabled: "(No cookie has been set yet)"})
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_start_day_options
|
54
|
+
year = prompt.select("Which Year?", Aocli::Values::START_DAY_YEARS)
|
55
|
+
day = prompt.select("Which Day?", Aocli::Values::START_DAY_DAYS)
|
56
|
+
options[:date] = Date.new(year, 12, day)
|
57
|
+
options[:output_destination] = "./"
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_save_cookie_options
|
61
|
+
options[:cookie] = prompt.ask("Paste your cookie and it will be saved:")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Aocli
|
2
|
+
module Commands
|
3
|
+
module SaveCookie
|
4
|
+
def self.run!(options)
|
5
|
+
Aocli::FileUtils.touch_file(Aocli::Values::CONFIG_FILE_PATH)
|
6
|
+
File.write(Aocli::Values::CONFIG_FILE_PATH, {cookie: options[:cookie]}.to_yaml)
|
7
|
+
|
8
|
+
puts <<~MSG
|
9
|
+
### Cookie saved to #{Aocli::Values::CONFIG_FILE_PATH} ###
|
10
|
+
|
11
|
+
If you ever need to reset this cookie, you can use the save cookie command again
|
12
|
+
or simply edit that file.
|
13
|
+
MSG
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Aocli
|
2
|
+
module Commands
|
3
|
+
class StartDay
|
4
|
+
def self.run!(options)
|
5
|
+
new(
|
6
|
+
date: options[:date],
|
7
|
+
output_destination: options[:output_destination],
|
8
|
+
).run!
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(date:, output_destination:)
|
12
|
+
@date = date
|
13
|
+
@output_destination = output_destination
|
14
|
+
@main_file_path = File.join(output_destination, date.year.to_s, "day_#{date.day}", "main.rb")
|
15
|
+
@input_file_path = File.join(output_destination, date.year.to_s, "day_#{date.day}", "input.txt")
|
16
|
+
end
|
17
|
+
|
18
|
+
def run!
|
19
|
+
Aocli::FileUtils.touch_file(main_file_path)
|
20
|
+
Aocli::FileUtils.touch_file(input_file_path)
|
21
|
+
File.write(main_file_path, main_content)
|
22
|
+
File.write(input_file_path, input_content)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
attr_reader :date, :output_destination, :main_file_path, :input_file_path
|
27
|
+
|
28
|
+
def main_content
|
29
|
+
problem_description = Aocli::AdventOfCode.get_problem_description(
|
30
|
+
year: date.year,
|
31
|
+
day: date.day,
|
32
|
+
)
|
33
|
+
|
34
|
+
content = Aocli::FileUtils.insert_lines(
|
35
|
+
Aocli::FileUtils.wrap_lines(problem_description).split("\n").map { _1 == "" ? "#" : "# #{_1}" },
|
36
|
+
into: Aocli::Content::Main.content,
|
37
|
+
after: "##### Part One Description #####",
|
38
|
+
)
|
39
|
+
|
40
|
+
Aocli::FileUtils.replace_line(
|
41
|
+
content,
|
42
|
+
"# __load_input__",
|
43
|
+
'input = File.read("#{__FILE__}".gsub("main.rb", "input.txt"))'
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def input_content
|
48
|
+
Aocli::AdventOfCode.get_problem_inputs(
|
49
|
+
year: date.year,
|
50
|
+
day: date.day,
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Aocli
|
2
|
+
module Content
|
3
|
+
module Main
|
4
|
+
def self.content
|
5
|
+
<<~RUBY
|
6
|
+
##### Part One Description #####
|
7
|
+
|
8
|
+
class Solution
|
9
|
+
attr_accessor :input
|
10
|
+
def initialize(input)
|
11
|
+
@input = input
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.run!(input)
|
15
|
+
new(parse_input(input)).run!
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.parse_input(input)
|
19
|
+
# Parse input
|
20
|
+
input
|
21
|
+
end
|
22
|
+
|
23
|
+
def run!
|
24
|
+
# Solve input
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# __load_input__
|
29
|
+
puts Solution.run!(input)
|
30
|
+
RUBY
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require("yaml")
|
2
|
+
|
3
|
+
module Aocli
|
4
|
+
module CookieRetriever
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def call
|
8
|
+
return unless file_exists?
|
9
|
+
|
10
|
+
config = YAML.load_file(Aocli::Values::CONFIG_FILE_PATH)
|
11
|
+
config[:cookie]
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_exists?
|
15
|
+
File.file?(Aocli::Values::CONFIG_FILE_PATH)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Aocli
|
2
|
+
module FileUtils
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def wrap_lines(content, wrap_at: 80)
|
6
|
+
content
|
7
|
+
.split("\n")
|
8
|
+
.map { wrap_line(_1, wrap_at: wrap_at) }
|
9
|
+
.flatten
|
10
|
+
.join("\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
def wrap_line(line, wrap_at:)
|
14
|
+
return line unless line.length > wrap_at
|
15
|
+
|
16
|
+
char_count = 0
|
17
|
+
results = []
|
18
|
+
current_line = ""
|
19
|
+
|
20
|
+
line.split(" ").each do |word|
|
21
|
+
if (current_line.length + word.length + 1) > wrap_at
|
22
|
+
results << current_line.strip
|
23
|
+
current_line = word
|
24
|
+
char_count = word.length
|
25
|
+
else
|
26
|
+
current_line += " #{word}"
|
27
|
+
char_count += word.length + 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
results << current_line.strip unless current_line == ""
|
31
|
+
results
|
32
|
+
end
|
33
|
+
|
34
|
+
def insert_lines(lines, into:, after:)
|
35
|
+
into_array = into.split("\n")
|
36
|
+
insert_index = into_array.index(after)
|
37
|
+
raise(StandardError, "Cannot find after #{after.inspect}") if insert_index.nil?
|
38
|
+
|
39
|
+
lines.reverse.each do |line|
|
40
|
+
into_array.insert(insert_index + 1, line)
|
41
|
+
end
|
42
|
+
into_array.join("\n")
|
43
|
+
end
|
44
|
+
|
45
|
+
def replace_line(lines, line_to_replace, replace_with)
|
46
|
+
lines.split("\n").map { _1 == line_to_replace ? replace_with : _1 }.join("\n")
|
47
|
+
end
|
48
|
+
|
49
|
+
def touch_file(file_path)
|
50
|
+
::FileUtils.mkdir_p(File.join(file_path.split("/")[0..-2]))
|
51
|
+
::FileUtils.touch(file_path)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/aocli/values.rb
ADDED
data/lib/aocli.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require("aocli/advent_of_code")
|
4
|
+
require("aocli/cli")
|
5
|
+
require("aocli/commands/save_cookie")
|
6
|
+
require("aocli/commands/start_day")
|
7
|
+
require("aocli/file_utils")
|
8
|
+
require("aocli/content/main")
|
9
|
+
require("aocli/version")
|
10
|
+
require("aocli/cookie_retriever")
|
11
|
+
require("aocli/values")
|
12
|
+
|
13
|
+
require("fileutils")
|
14
|
+
require("tty-prompt")
|
15
|
+
require("nokogiri")
|
16
|
+
require("active_support/core_ext/string")
|
17
|
+
|
18
|
+
module Aocli
|
19
|
+
end
|
Binary file
|
data/sig/aocli.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aocli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blake Astley
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-prompt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.23.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.23.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '11.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '11.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '13.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '13.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: timecop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.9'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '6.1'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '6.1'
|
153
|
+
description: Command line application to retrieve advent of code challenges and create
|
154
|
+
boilerplate solution code
|
155
|
+
email:
|
156
|
+
- astley92@hotmail.com
|
157
|
+
executables:
|
158
|
+
- aocli
|
159
|
+
extensions: []
|
160
|
+
extra_rdoc_files: []
|
161
|
+
files:
|
162
|
+
- ".rspec"
|
163
|
+
- ".rubocop.yml"
|
164
|
+
- CHANGELOG.md
|
165
|
+
- CODE_OF_CONDUCT.md
|
166
|
+
- Gemfile
|
167
|
+
- Gemfile.lock
|
168
|
+
- LICENSE.txt
|
169
|
+
- README.md
|
170
|
+
- Rakefile
|
171
|
+
- exe/aocli
|
172
|
+
- lib/aocli.rb
|
173
|
+
- lib/aocli/advent_of_code.rb
|
174
|
+
- lib/aocli/advent_of_code/client.rb
|
175
|
+
- lib/aocli/cli.rb
|
176
|
+
- lib/aocli/commands/save_cookie.rb
|
177
|
+
- lib/aocli/commands/start_day.rb
|
178
|
+
- lib/aocli/content/main.rb
|
179
|
+
- lib/aocli/cookie_retriever.rb
|
180
|
+
- lib/aocli/file_utils.rb
|
181
|
+
- lib/aocli/values.rb
|
182
|
+
- lib/aocli/version.rb
|
183
|
+
- public/aocli-cookie-helper.png
|
184
|
+
- sig/aocli.rbs
|
185
|
+
homepage: https://github.com/astley92/aocli
|
186
|
+
licenses:
|
187
|
+
- MIT
|
188
|
+
metadata:
|
189
|
+
allowed_push_host: https://rubygems.org
|
190
|
+
homepage_uri: https://github.com/astley92/aocli
|
191
|
+
source_code_uri: https://github.com/astley92/aocli
|
192
|
+
changelog_uri: https://github.com/astley92/aocli/CHANGELOG.md
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 2.6.0
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
requirements: []
|
208
|
+
rubygems_version: 3.3.25
|
209
|
+
signing_key:
|
210
|
+
specification_version: 4
|
211
|
+
summary: Command line application to retrieve advent of code challenges
|
212
|
+
test_files: []
|