aoc_generator 0.1.1 → 0.1.3
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/CHANGELOG.md +11 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +4 -4
- data/README.md +3 -4
- data/lib/advent_of_code_generator/cli.rb +4 -1
- data/lib/advent_of_code_generator/generator.rb +7 -5
- data/lib/advent_of_code_generator/html_parser.rb +50 -0
- data/lib/advent_of_code_generator/scraper.rb +4 -2
- data/lib/advent_of_code_generator.rb +1 -1
- metadata +6 -8
- data/.rspec +0 -3
- data/.rubocop.yml +0 -20
- data/Rakefile +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b769226917de985f62166b06a18ac48433df5e5ca362fdfc7248338d368ce39
|
4
|
+
data.tar.gz: 9f1be6d33fe107041e8ebcbc90c9dc67b05d5ad27506a84ee2ebe5239cf4920b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fad21368f7c4033a73670fdb2dece5a1ed468de3e0075d50426b821d65a3e15ae840bf2c8f6e20f5e8070f836ffe21bb72eb7abd100162bed5ee60101ca8821
|
7
|
+
data.tar.gz: 1ec320f03139f386435f78e21f3922e840a36433795f7e34421ff4d464b53073497c7c742da1998a025b15e31c1c34e719a5f008cd049a8ad65d2351f1ad8234
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [0.1.
|
3
|
+
## [0.1.3] - 2024-11-28
|
4
|
+
|
5
|
+
- Allow to read a AOC_SESSION environment variable
|
6
|
+
- Change file names
|
7
|
+
- Convert HTML to Markdown
|
8
|
+
|
9
|
+
## [0.1.2]
|
10
|
+
|
11
|
+
- [Fix] Add the correct FileUtils gem
|
12
|
+
|
13
|
+
## [0.1.1]
|
4
14
|
|
5
15
|
- Add FileUtils gem
|
6
16
|
- Specify dependencies
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
aoc_generator (0.1.
|
5
|
-
|
4
|
+
aoc_generator (0.1.3)
|
5
|
+
fileutils (~> 1.7)
|
6
6
|
nokogiri (~> 1.16)
|
7
7
|
thor (~> 1.3)
|
8
8
|
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
irb (~> 1.10)
|
21
21
|
reline (>= 0.3.8)
|
22
22
|
diff-lcs (1.5.1)
|
23
|
-
|
23
|
+
fileutils (1.7.3)
|
24
24
|
hashdiff (1.1.2)
|
25
25
|
io-console (0.7.2)
|
26
26
|
irb (1.14.1)
|
@@ -95,7 +95,7 @@ PLATFORMS
|
|
95
95
|
DEPENDENCIES
|
96
96
|
aoc_generator!
|
97
97
|
debug (~> 1.9)
|
98
|
-
|
98
|
+
fileutils (~> 1.7)
|
99
99
|
nokogiri (~> 1.16)
|
100
100
|
rake (~> 13.2)
|
101
101
|
rspec (~> 3.13)
|
data/README.md
CHANGED
@@ -16,12 +16,11 @@ A Ruby gem that generates daily puzzle templates for Advent of Code.
|
|
16
16
|
|
17
17
|
```sh
|
18
18
|
-y, [--year=N] # Defaults to the current year.
|
19
|
-
# Default: 2024
|
20
19
|
-d, [--day=N] # Defaults to the current day.
|
21
|
-
# Default: 28
|
22
20
|
-u, [--username=USERNAME] # Files will be generated in a directory with this name. Useful for multi-user repos.
|
23
21
|
# Default: advent_of_code
|
24
22
|
-s, [--session=SESSION] # Your adventofcode.com session key. Necessary for scraping data files and specs for part two.
|
23
|
+
# Default: reads AOC_SESSION environment variable if it exists.
|
25
24
|
```
|
26
25
|
|
27
26
|
## Generated file structure
|
@@ -32,8 +31,8 @@ adventofcode/
|
|
32
31
|
└── year_2024/
|
33
32
|
|
|
34
33
|
└── day_01/
|
35
|
-
├──
|
36
|
-
├──
|
34
|
+
├── day_01.rb
|
35
|
+
├── day_01_spec.rb
|
37
36
|
├── data.txt
|
38
37
|
└── README.md
|
39
38
|
```
|
@@ -32,7 +32,10 @@ module AdventOfCodeGenerator
|
|
32
32
|
method_option :session,
|
33
33
|
required: false,
|
34
34
|
aliases: "-s",
|
35
|
-
desc: "Your adventofcode.com session key.
|
35
|
+
desc: "Your adventofcode.com session key. " \
|
36
|
+
"Necessary for scraping data files and specs for part two. " \
|
37
|
+
"Defaults to a AOC_SESSION environment variable if it exists.",
|
38
|
+
default: ENV.fetch("AOC_SESSION", nil)
|
36
39
|
|
37
40
|
def generate
|
38
41
|
scraper = AdventOfCodeGenerator::Scraper.new(options)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "fileutils"
|
4
|
+
|
3
5
|
module AdventOfCodeGenerator
|
4
6
|
# Creates directory structure and files for daily Advent of Code puzzles:
|
5
7
|
#
|
@@ -10,8 +12,8 @@ module AdventOfCodeGenerator
|
|
10
12
|
# └── year_2024/
|
11
13
|
# |
|
12
14
|
# └── day_01/
|
13
|
-
# ├──
|
14
|
-
# ├──
|
15
|
+
# ├── day_01.rb
|
16
|
+
# ├── day_01_spec.rb
|
15
17
|
# ├── data.txt
|
16
18
|
# └── README.md
|
17
19
|
#
|
@@ -56,7 +58,7 @@ module AdventOfCodeGenerator
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def main_file
|
59
|
-
path = "#{daily_directory}/
|
61
|
+
path = "#{daily_directory}/day_#{@day}.rb"
|
60
62
|
content = <<~RUBY
|
61
63
|
# frozen_string_literal: true
|
62
64
|
|
@@ -83,11 +85,11 @@ module AdventOfCodeGenerator
|
|
83
85
|
end
|
84
86
|
|
85
87
|
def spec_file
|
86
|
-
path = "#{daily_directory}/
|
88
|
+
path = "#{daily_directory}/day_#{@day}_spec.rb"
|
87
89
|
content = <<~RUBY
|
88
90
|
# frozen_string_literal: true
|
89
91
|
|
90
|
-
require_relative "
|
92
|
+
require_relative "day_#{@day}"
|
91
93
|
|
92
94
|
RSpec.describe #{@username.capitalize}::Year#{@year}::Day#{@day} do
|
93
95
|
subject(:puzzle) { described_class.new(input) }
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "nokogiri"
|
4
|
+
|
5
|
+
module AdventOfCodeGenerator
|
6
|
+
# Converts HTML puzzle descriptions from adventofcode.com into markdown format.
|
7
|
+
class HTMLParser
|
8
|
+
def initialize(input)
|
9
|
+
@input = input
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
articles.map do |node|
|
14
|
+
process_article(node)
|
15
|
+
end.join("\n").strip
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def articles
|
21
|
+
doc = Nokogiri::HTML(@input)
|
22
|
+
doc.css("article")
|
23
|
+
end
|
24
|
+
|
25
|
+
def process_article(article)
|
26
|
+
article.children.map { |node| process_node(node) }.compact
|
27
|
+
end
|
28
|
+
|
29
|
+
def process_node(node)
|
30
|
+
case node.name
|
31
|
+
when "h2"
|
32
|
+
"## #{node.text}\n"
|
33
|
+
when "p"
|
34
|
+
"#{process_paragraph(node)}\n"
|
35
|
+
when "pre"
|
36
|
+
"```sh\n#{node.text.strip}\n```\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def process_paragraph(para)
|
41
|
+
para.inner_html
|
42
|
+
.gsub(%r{<a[^>]*href="([^"]*)"[^>]*>(.*?)</a>}, '[\2](\1)')
|
43
|
+
.gsub(%r{<code><em>(.*?)</em></code>}, '**`\1`**')
|
44
|
+
.gsub(%r{<em><code>(.*?)</code></em>}, '**`\1`**')
|
45
|
+
.gsub(%r{<em.*?>(.*?)</em>}, '**\1**')
|
46
|
+
.gsub(%r{<code>(.*?)</code>}, '`\1`')
|
47
|
+
.gsub(/<[^>]*>/, "")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "net/http"
|
4
|
+
require_relative "html_parser"
|
4
5
|
|
5
6
|
module AdventOfCodeGenerator
|
6
7
|
# Fetches puzzle descriptions and input data from adventofcode.com.
|
7
8
|
class Scraper
|
8
|
-
def initialize(options)
|
9
|
+
def initialize(options, parser = AdventOfCodeGenerator::HTMLParser)
|
9
10
|
@year = options[:year]
|
10
11
|
@day = options[:day]
|
11
12
|
@session_key = options[:session]
|
13
|
+
@parser = parser
|
12
14
|
end
|
13
15
|
|
14
16
|
def puzzle_description
|
@@ -17,7 +19,7 @@ module AdventOfCodeGenerator
|
|
17
19
|
uri = URI("https://adventofcode.com/#{@year}/day/#{@day}")
|
18
20
|
response = Net::HTTP.get_response(uri, headers)
|
19
21
|
|
20
|
-
response.body
|
22
|
+
@parser.new(response.body).call
|
21
23
|
end
|
22
24
|
|
23
25
|
def input_data
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aoc_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: fileutils
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,20 +63,18 @@ executables:
|
|
63
63
|
extensions: []
|
64
64
|
extra_rdoc_files: []
|
65
65
|
files:
|
66
|
-
- ".rspec"
|
67
|
-
- ".rubocop.yml"
|
68
66
|
- ".tool-versions"
|
69
67
|
- CHANGELOG.md
|
70
68
|
- Gemfile
|
71
69
|
- Gemfile.lock
|
72
70
|
- README.md
|
73
|
-
- Rakefile
|
74
71
|
- bin/console
|
75
72
|
- bin/setup
|
76
73
|
- exe/aoc
|
77
74
|
- lib/advent_of_code_generator.rb
|
78
75
|
- lib/advent_of_code_generator/cli.rb
|
79
76
|
- lib/advent_of_code_generator/generator.rb
|
77
|
+
- lib/advent_of_code_generator/html_parser.rb
|
80
78
|
- lib/advent_of_code_generator/scraper.rb
|
81
79
|
homepage: https://github.com/cheddachedda/advent_of_code_generator
|
82
80
|
licenses: []
|
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- rubocop-rake
|
3
|
-
- rubocop-rspec
|
4
|
-
|
5
|
-
AllCops:
|
6
|
-
DisplayCopNames: true
|
7
|
-
NewCops: enable
|
8
|
-
TargetRubyVersion: 3.3
|
9
|
-
|
10
|
-
Metrics/MethodLength:
|
11
|
-
CountAsOne: heredoc
|
12
|
-
|
13
|
-
Style/StringLiterals:
|
14
|
-
EnforcedStyle: double_quotes
|
15
|
-
|
16
|
-
Style/StringLiteralsInInterpolation:
|
17
|
-
EnforcedStyle: double_quotes
|
18
|
-
|
19
|
-
RSpec/ExampleLength:
|
20
|
-
Enabled: false
|