green_day 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/README.md +2 -2
- data/green_day.gemspec +2 -0
- data/lib/green_day/atcoder_client.rb +9 -3
- data/lib/green_day/cli.rb +13 -4
- data/lib/green_day/contest.rb +3 -4
- data/lib/green_day/task.rb +3 -5
- data/lib/green_day/version.rb +1 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dec8f7c9c721bbd5e652f18959de01d9a90d6ec3a1d7caf57eed76aa31ad9378
|
4
|
+
data.tar.gz: c2afef234af2730e3a2ac2fff659dcfc85489b0292d2395f6382bab3a73d2f37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a6f108363c5e35d96b5739184318260d64da36187a259449ac5fde602d6d70a16d7bfab01f64f4a8794fcbbfa49322bdfb13ae408a7ffd0299820a5eac2f806
|
7
|
+
data.tar.gz: 9e6d545f778fd361853c082fcd1d67564d59edef0bbe88ac2f47189c0bcc1b1c4603f35374cf0d8728c455b8c0ed33f18e96eb54ddf5e8432a72a688d1684de8
|
data/.github/workflows/ruby.yml
CHANGED
data/README.md
CHANGED
@@ -18,11 +18,11 @@ Or install it yourself as:
|
|
18
18
|
$ gem install green_day
|
19
19
|
|
20
20
|
## Usage
|
21
|
-
login(this command stores your cookie as
|
21
|
+
login(this command stores your cookie as `.cookie-store` in current directory)
|
22
22
|
|
23
23
|
$ bundle exec green_day login
|
24
24
|
|
25
|
-
If you want to delete session, remove
|
25
|
+
If you want to delete session, remove `.cookie-store`
|
26
26
|
|
27
27
|
This command creates directory and spec.
|
28
28
|
|
data/green_day.gemspec
CHANGED
@@ -25,9 +25,11 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.bindir = 'exe'
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
|
+
spec.add_dependency 'colorize'
|
28
29
|
spec.add_dependency 'faraday', '< 1.0'
|
29
30
|
spec.add_dependency 'faraday-cookie_jar'
|
30
31
|
spec.add_dependency 'nokogiri'
|
32
|
+
spec.add_dependency 'parallel'
|
31
33
|
spec.add_dependency 'rspec', '~> 3.0'
|
32
34
|
spec.add_dependency 'thor'
|
33
35
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
@@ -8,7 +8,7 @@ require 'nokogiri'
|
|
8
8
|
module GreenDay
|
9
9
|
class AtcoderClient
|
10
10
|
ATCODER_ENDPOINT = 'https://atcoder.jp'
|
11
|
-
|
11
|
+
COOKIE_FILE_NAME = '.cookie-store'
|
12
12
|
attr_reader :client, :cookie_jar
|
13
13
|
|
14
14
|
def initialize
|
@@ -57,14 +57,20 @@ module GreenDay
|
|
57
57
|
raise Error, CGI.unescape(select_flash_cookie.value).split('.').shift
|
58
58
|
end
|
59
59
|
|
60
|
-
cookie_jar.save(
|
60
|
+
cookie_jar.save(COOKIE_FILE_NAME)
|
61
61
|
end
|
62
62
|
|
63
63
|
private
|
64
64
|
|
65
65
|
def create_or_load_cookie_jar
|
66
66
|
jar = HTTP::CookieJar.new
|
67
|
-
|
67
|
+
if File.exist?(COOKIE_FILE_NAME)
|
68
|
+
jar.load(COOKIE_FILE_NAME)
|
69
|
+
elsif File.exist?('cookie-store')
|
70
|
+
warn 'cookie-store needs rename .cookie-store'
|
71
|
+
jar.load('cookie-store')
|
72
|
+
end
|
73
|
+
|
68
74
|
jar
|
69
75
|
end
|
70
76
|
|
data/lib/green_day/cli.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'thor'
|
4
|
+
require 'parallel'
|
5
|
+
require 'colorize'
|
6
|
+
require 'io/console'
|
4
7
|
require_relative 'atcoder_client'
|
5
8
|
require_relative 'contest'
|
6
9
|
require_relative 'test_builder'
|
@@ -11,22 +14,28 @@ module GreenDay
|
|
11
14
|
desc 'login Atcoder', 'login Atcoder and save session'
|
12
15
|
def login
|
13
16
|
print 'username:'
|
14
|
-
username = STDIN.gets
|
17
|
+
username = STDIN.gets(chomp: true)
|
15
18
|
print 'password:'
|
16
|
-
password = STDIN.gets.
|
19
|
+
password = STDIN.noecho { |stdin| stdin.gets(chomp: true) }.tap { puts }
|
17
20
|
|
18
21
|
AtcoderClient.new.login(username, password)
|
22
|
+
puts(
|
23
|
+
"Successfully created #{AtcoderClient::COOKIE_FILE_NAME}"
|
24
|
+
.colorize(:green)
|
25
|
+
)
|
19
26
|
end
|
20
27
|
|
21
28
|
desc 'new [contest name]', 'create contest workspace and spec'
|
22
29
|
def new(contest_name)
|
23
|
-
contest = Contest.new(contest_name)
|
30
|
+
contest = Contest.new(contest_name, AtcoderClient.new)
|
24
31
|
FileUtils.makedirs("#{contest_name}/spec")
|
25
32
|
|
26
|
-
contest.tasks
|
33
|
+
Parallel.each(contest.tasks) do |task|
|
27
34
|
create_submit_file!(contest_name, task)
|
28
35
|
create_spec_file!(contest_name, task)
|
29
36
|
end
|
37
|
+
|
38
|
+
puts "Successfully created #{contest_name} directory".colorize(:green)
|
30
39
|
end
|
31
40
|
|
32
41
|
private
|
data/lib/green_day/contest.rb
CHANGED
@@ -7,13 +7,12 @@ module GreenDay
|
|
7
7
|
class Contest
|
8
8
|
attr_reader :atcoder_client, :name, :tasks
|
9
9
|
|
10
|
-
def initialize(contest_name)
|
11
|
-
client = AtcoderClient.new
|
10
|
+
def initialize(contest_name, client)
|
12
11
|
raise GreenDay::Error 'cant find contest' unless client.contest_exist?(contest_name)
|
13
12
|
|
14
13
|
@name = contest_name
|
15
|
-
@tasks = client.fetch_task_codes(self)
|
16
|
-
Task.new(self, task_code)
|
14
|
+
@tasks = Parallel.map(client.fetch_task_codes(self)) do |task_code|
|
15
|
+
Task.new(self, task_code, client)
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
data/lib/green_day/task.rb
CHANGED
@@ -3,17 +3,15 @@
|
|
3
3
|
module GreenDay
|
4
4
|
class Task
|
5
5
|
attr_reader :contest, :code, :input_output_hash
|
6
|
-
def initialize(contest, code)
|
6
|
+
def initialize(contest, code, client)
|
7
7
|
@contest = contest
|
8
8
|
@code = code
|
9
|
-
@input_output_hash = create_input_output_hash
|
9
|
+
@input_output_hash = create_input_output_hash(client)
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
def create_input_output_hash
|
15
|
-
client = AtcoderClient.new
|
16
|
-
|
14
|
+
def create_input_output_hash(client)
|
17
15
|
input_samples, output_samples =
|
18
16
|
client.fetch_inputs_and_outputs(contest, self)
|
19
17
|
|
data/lib/green_day/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: green_day
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- qwyng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: faraday
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: parallel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rspec
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|