green_day 0.4.0 → 0.5.0
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/.github/workflows/publish_to_rubygems.yml +31 -0
- data/.github/workflows/ruby.yml +18 -9
- data/.rubocop.yml +2 -2
- data/README.md +1 -3
- data/green_day.gemspec +1 -1
- data/lib/green_day/atcoder_client.rb +8 -31
- data/lib/green_day/cli.rb +2 -2
- data/lib/green_day/contest.rb +21 -7
- data/lib/green_day/task.rb +22 -7
- data/lib/green_day/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6db900740eb86bf00384ad3f97895ecd146d5f112f96db362c28a28cbfb391f
|
4
|
+
data.tar.gz: c4f4a09dd97c634b671434735896294c13f5ad3992d97378db3cde64e804efae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15d1dfd04be33f629ec7f6f74ff7666175e39bd62e3dcb80f2d5ae936c86001ba479db6fe2a084839d7e12fedaede50b3d85c9c65d4ae9c88700127204c4a33e
|
7
|
+
data.tar.gz: c5e5b31671f907460705f3baac9e9ebc6a0142fb3d2678e1783b3b8a382e266cb06cf4e793a096768632b8451f2925d6968550c32ae5ef355738f3ee23e8153c
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Publish to RubyGems
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
name: Build + Publish
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
permissions:
|
11
|
+
packages: write
|
12
|
+
contents: read
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v3
|
16
|
+
- name: Set up Ruby 3.1
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 3.1
|
20
|
+
- run: bundle install
|
21
|
+
|
22
|
+
- name: Publish to RubyGems
|
23
|
+
run: |
|
24
|
+
mkdir -p $HOME/.gem
|
25
|
+
touch $HOME/.gem/credentials
|
26
|
+
chmod 0600 $HOME/.gem/credentials
|
27
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
28
|
+
gem build *.gemspec
|
29
|
+
gem push *.gem
|
30
|
+
env:
|
31
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.github/workflows/ruby.yml
CHANGED
@@ -10,25 +10,34 @@ jobs:
|
|
10
10
|
runs-on: ubuntu-latest
|
11
11
|
strategy:
|
12
12
|
matrix:
|
13
|
-
ruby:
|
13
|
+
ruby-version:
|
14
14
|
- 2.7.1 # AtCoder公式が使用しているrubyは2.7.1
|
15
|
-
- 3.1
|
15
|
+
- 3.1
|
16
16
|
steps:
|
17
|
-
- uses: actions/checkout@
|
18
|
-
- name: Set up Ruby ${{ matrix.ruby }}
|
17
|
+
- uses: actions/checkout@v3
|
18
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
19
19
|
uses: ruby/setup-ruby@v1
|
20
20
|
with:
|
21
|
-
ruby-version: ${{ matrix.ruby }}
|
22
|
-
- name:
|
21
|
+
ruby-version: ${{ matrix.ruby-version }}
|
22
|
+
- name: Bundle install
|
23
23
|
run: bundle install
|
24
|
-
- name:
|
25
|
-
run: bundle exec rubocop
|
26
|
-
- name: Rspec
|
24
|
+
- name: Run Rspec
|
27
25
|
env:
|
28
26
|
USER_NAME: ${{ secrets.USER_NAME }}
|
29
27
|
PASSWORD: ${{ secrets.PASSWORD }}
|
30
28
|
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
31
29
|
run: script -e -c "rake spec"
|
30
|
+
rubocop:
|
31
|
+
runs-on: ubuntu-latest
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@v3
|
34
|
+
- uses: ruby/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
ruby-version: 3.1
|
37
|
+
- name: Bundle install
|
38
|
+
run: bundle install
|
39
|
+
- name: Run rubocop
|
40
|
+
run: bundle exec rubocop
|
32
41
|
|
33
42
|
|
34
43
|
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -52,8 +52,6 @@ For example
|
|
52
52
|
Example of output spec
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
require 'rspec'
|
56
|
-
|
57
55
|
RSpec.describe 'test' do
|
58
56
|
it 'test with "2 900\\n"' do
|
59
57
|
io = IO.popen("ruby abc150/A.rb", "w+")
|
@@ -94,4 +92,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
94
92
|
|
95
93
|
## Code of Conduct
|
96
94
|
|
97
|
-
Everyone interacting in the GreenDay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
95
|
+
Everyone interacting in the GreenDay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/QWYNG/green_day/blob/master/CODE_OF_CONDUCT.md).
|
data/green_day.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
|
29
29
|
spec.add_dependency 'colorize'
|
30
|
-
spec.add_dependency 'faraday'
|
30
|
+
spec.add_dependency 'faraday'
|
31
31
|
spec.add_dependency 'faraday-cookie_jar'
|
32
32
|
spec.add_dependency 'nokogiri'
|
33
33
|
spec.add_dependency 'parallel'
|
@@ -20,28 +20,9 @@ module GreenDay
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
res = client.get(
|
25
|
-
res.
|
26
|
-
end
|
27
|
-
|
28
|
-
def fetch_task_codes(contest)
|
29
|
-
body = get_parsed_body("contests/#{contest.name}/tasks")
|
30
|
-
|
31
|
-
# 3問だったら<tbody>の中に<tr>が3 * 2個 </tbody> が1mh個
|
32
|
-
tasks_size = ((body.at('tbody').children.size - 1) / 2.0).ceil
|
33
|
-
('A'..'ZZ').to_a.shift(tasks_size)
|
34
|
-
end
|
35
|
-
|
36
|
-
def fetch_inputs_and_outputs(contest, task)
|
37
|
-
contest_name = contest.name
|
38
|
-
path = "contests/#{contest_name}/tasks/#{contest_name}_#{task.code.downcase}"
|
39
|
-
body = get_parsed_body(path)
|
40
|
-
samples = body.css('.lang-ja > .part > section > pre').map { |e| e.children.text }
|
41
|
-
|
42
|
-
inputs, outputs = samples.partition.with_index { |_sample, i| i.even? }
|
43
|
-
|
44
|
-
[inputs, outputs]
|
23
|
+
def get_parsed_body(path)
|
24
|
+
res = client.get(path)
|
25
|
+
Nokogiri::HTML.parse(res.body)
|
45
26
|
end
|
46
27
|
|
47
28
|
def login(username, password)
|
@@ -54,7 +35,7 @@ module GreenDay
|
|
54
35
|
|
55
36
|
unless login_succeed?
|
56
37
|
## ex error:Username or Password is incorrect
|
57
|
-
raise Error, CGI.unescape(
|
38
|
+
raise Error, CGI.unescape(flash_cookie.value).split('.').shift
|
58
39
|
end
|
59
40
|
|
60
41
|
cookie_jar.save(COOKIE_FILE_NAME)
|
@@ -83,17 +64,13 @@ module GreenDay
|
|
83
64
|
end
|
84
65
|
|
85
66
|
def login_succeed?
|
86
|
-
flash_cookie = select_flash_cookie
|
87
67
|
flash_cookie.value.include?('Welcome')
|
88
68
|
end
|
89
69
|
|
90
|
-
def
|
91
|
-
cookie_jar.
|
92
|
-
|
93
|
-
|
94
|
-
def get_parsed_body(path)
|
95
|
-
res = client.get(path)
|
96
|
-
Nokogiri::HTML.parse(res.body)
|
70
|
+
def flash_cookie
|
71
|
+
@flash_cookie ||= cookie_jar.cookies("#{ATCODER_ENDPOINT}/login").find do |cookie|
|
72
|
+
cookie.name == 'REVEL_FLASH'
|
73
|
+
end
|
97
74
|
end
|
98
75
|
end
|
99
76
|
end
|
data/lib/green_day/cli.rb
CHANGED
@@ -53,11 +53,11 @@ module GreenDay
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def submit_file_path(task)
|
56
|
-
"#{task.contest.name}/#{task.
|
56
|
+
"#{task.contest.name}/#{task.name}.rb"
|
57
57
|
end
|
58
58
|
|
59
59
|
def spec_file_path(task)
|
60
|
-
"#{task.contest.name}/spec/#{task.
|
60
|
+
"#{task.contest.name}/spec/#{task.name}_spec.rb"
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
data/lib/green_day/contest.rb
CHANGED
@@ -1,22 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'forwardable'
|
4
4
|
require_relative 'task'
|
5
5
|
|
6
6
|
module GreenDay
|
7
7
|
class Contest
|
8
|
-
|
8
|
+
extend Forwardable
|
9
|
+
delegate get_parsed_body: :@client
|
9
10
|
|
10
|
-
|
11
|
-
raise GreenDay::Error 'cant find contest' unless client.contest_exist?(contest_name)
|
11
|
+
attr_reader :name, :tasks
|
12
12
|
|
13
|
+
def initialize(contest_name, client)
|
14
|
+
@client = client
|
13
15
|
@name = contest_name
|
14
16
|
|
15
|
-
|
17
|
+
task_names_and_paths = fetch_task_names_and_paths
|
16
18
|
@tasks =
|
17
|
-
Parallel.map(
|
18
|
-
|
19
|
+
Parallel.map(task_names_and_paths,
|
20
|
+
in_threads: THREAD_COUNT) do |task_name, task_path|
|
21
|
+
Task.new(self, task_name, task_path, @client)
|
19
22
|
end
|
20
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def fetch_task_names_and_paths
|
28
|
+
body = get_parsed_body("contests/#{name}/tasks")
|
29
|
+
task_elements = body.search('tbody tr td:first a')
|
30
|
+
|
31
|
+
task_elements.to_h do |element|
|
32
|
+
[element.text, element[:href]]
|
33
|
+
end
|
34
|
+
end
|
21
35
|
end
|
22
36
|
end
|
data/lib/green_day/task.rb
CHANGED
@@ -1,22 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'forwardable'
|
4
|
+
|
3
5
|
module GreenDay
|
4
6
|
class Task
|
5
|
-
|
7
|
+
extend Forwardable
|
8
|
+
delegate get_parsed_body: :@client
|
9
|
+
|
10
|
+
attr_reader :contest, :name, :path, :sample_answers
|
6
11
|
|
7
|
-
def initialize(contest,
|
12
|
+
def initialize(contest, name, path, client)
|
13
|
+
@client = client
|
8
14
|
@contest = contest
|
9
|
-
@
|
10
|
-
@
|
15
|
+
@name = name
|
16
|
+
@path = path
|
17
|
+
@sample_answers = create_sample_answers_hash
|
11
18
|
end
|
12
19
|
|
13
20
|
private
|
14
21
|
|
15
|
-
def
|
16
|
-
input_samples, output_samples =
|
17
|
-
client.fetch_inputs_and_outputs(contest, self)
|
22
|
+
def create_sample_answers_hash
|
23
|
+
input_samples, output_samples = fetch_inputs_and_outputs
|
18
24
|
|
19
25
|
input_samples.zip(output_samples).to_h
|
20
26
|
end
|
27
|
+
|
28
|
+
def fetch_inputs_and_outputs
|
29
|
+
body = get_parsed_body(path)
|
30
|
+
samples = body.css('.lang-ja > .part > section > pre').map { |e| e.children.text }
|
31
|
+
|
32
|
+
inputs, outputs = samples.partition.with_index { |_sample, i| i.even? }
|
33
|
+
|
34
|
+
[inputs, outputs]
|
35
|
+
end
|
21
36
|
end
|
22
37
|
end
|
data/lib/green_day/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: green_day
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- qwyng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday-cookie_jar
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -242,6 +242,7 @@ executables:
|
|
242
242
|
extensions: []
|
243
243
|
extra_rdoc_files: []
|
244
244
|
files:
|
245
|
+
- ".github/workflows/publish_to_rubygems.yml"
|
245
246
|
- ".github/workflows/ruby.yml"
|
246
247
|
- ".gitignore"
|
247
248
|
- ".rspec"
|
@@ -284,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
285
|
- !ruby/object:Gem::Version
|
285
286
|
version: '0'
|
286
287
|
requirements: []
|
287
|
-
rubygems_version: 3.
|
288
|
+
rubygems_version: 3.3.7
|
288
289
|
signing_key:
|
289
290
|
specification_version: 4
|
290
291
|
summary: CLI tool for AtCoder and Ruby
|