acclir 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -5
- data/Gemfile.lock +18 -1
- data/README.md +37 -6
- data/acclir.gemspec +2 -0
- data/lib/acclir/at_coder/connection.rb +46 -0
- data/lib/acclir/at_coder/contest.rb +6 -8
- data/lib/acclir/at_coder/error.rb +12 -0
- data/lib/acclir/at_coder/login_session.rb +34 -0
- data/lib/acclir/at_coder/task.rb +6 -8
- data/lib/acclir/at_coder/user.rb +14 -0
- data/lib/acclir/at_coder.rb +12 -7
- data/lib/acclir/cli.rb +14 -0
- data/lib/acclir/version.rb +1 -1
- metadata +34 -3
- data/sig/acclir.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 509ae754ceb4809ba02d8ecde51e47f5959486196fb3a10239813fe5e835ba99
|
4
|
+
data.tar.gz: 4dfb3a86ffc3d056b837930dd3741a6ed24fcbffa0c2981103ab9b9e6f1908fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0849a1bcf63a8c2b83f0d656d6e839a5c2a835e343ab492bd6b130e711ac26ccc1798698b6f5a744566ef7d263a145ca149270ad693666d84b76822e52cbbd8c'
|
7
|
+
data.tar.gz: 44eb7e9aa9e7788e966fbcf4f44eabb78e88bc205ed99a6d11d6917c8d38fa7b51c238f45bfd3262818854e92653398c20c6a5f19b46fb60deddd9aebd0f8495
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
acclir (0.
|
4
|
+
acclir (0.2.0)
|
5
|
+
faraday (~> 2.7.2)
|
6
|
+
faraday-cookie_jar (~> 0.0.7)
|
5
7
|
minitest
|
6
8
|
nokogiri (~> 1.13.10)
|
7
9
|
thor (~> 1.2.1)
|
@@ -15,7 +17,18 @@ GEM
|
|
15
17
|
crack (0.4.5)
|
16
18
|
rexml
|
17
19
|
diff-lcs (1.5.0)
|
20
|
+
domain_name (0.5.20190701)
|
21
|
+
unf (>= 0.0.5, < 1.0.0)
|
22
|
+
faraday (2.7.2)
|
23
|
+
faraday-net_http (>= 2.0, < 3.1)
|
24
|
+
ruby2_keywords (>= 0.0.4)
|
25
|
+
faraday-cookie_jar (0.0.7)
|
26
|
+
faraday (>= 0.8.0)
|
27
|
+
http-cookie (~> 1.0.0)
|
28
|
+
faraday-net_http (3.0.2)
|
18
29
|
hashdiff (1.0.1)
|
30
|
+
http-cookie (1.0.5)
|
31
|
+
domain_name (~> 0.5)
|
19
32
|
json (2.6.3)
|
20
33
|
mini_portile2 (2.8.1)
|
21
34
|
minitest (5.17.0)
|
@@ -61,7 +74,11 @@ GEM
|
|
61
74
|
rubocop-ast (1.24.0)
|
62
75
|
parser (>= 3.1.1.0)
|
63
76
|
ruby-progressbar (1.11.0)
|
77
|
+
ruby2_keywords (0.0.5)
|
64
78
|
thor (1.2.1)
|
79
|
+
unf (0.1.4)
|
80
|
+
unf_ext
|
81
|
+
unf_ext (0.0.8.2)
|
65
82
|
unicode-display_width (2.3.0)
|
66
83
|
webmock (3.18.1)
|
67
84
|
addressable (>= 2.8.0)
|
data/README.md
CHANGED
@@ -4,19 +4,50 @@ AtCoder CLI developed in Ruby.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
8
|
-
|
9
7
|
Install the gem and add to the application's Gemfile by executing:
|
10
8
|
|
11
|
-
|
9
|
+
```
|
10
|
+
$ bundle add acclir
|
11
|
+
```
|
12
12
|
|
13
13
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
14
|
|
15
|
-
|
15
|
+
```
|
16
|
+
$ gem install acclir
|
17
|
+
```
|
16
18
|
|
17
19
|
## Usage
|
18
20
|
|
19
|
-
|
21
|
+
```
|
22
|
+
$ acclir help
|
23
|
+
Acclir commands:
|
24
|
+
acclir help [COMMAND] # Describe available commands or one specific command
|
25
|
+
acclir login # Login AtCoder
|
26
|
+
acclir new CONTEST_ID # Generate files for the contest
|
27
|
+
```
|
28
|
+
|
29
|
+
## Examples
|
30
|
+
|
31
|
+
First, login.
|
32
|
+
|
33
|
+
```
|
34
|
+
$ acclir login
|
35
|
+
```
|
36
|
+
|
37
|
+
Prepare for AtCoder Beginner Contest 284.
|
38
|
+
|
39
|
+
```
|
40
|
+
$ acclir new abc284
|
41
|
+
```
|
42
|
+
|
43
|
+
`abc284` is the ID assigned to the contest URL.
|
44
|
+
https://atcoder.jp/contests/abc284
|
45
|
+
|
46
|
+
Once the problem is solved, the test can be run.
|
47
|
+
|
48
|
+
```
|
49
|
+
$ ruby abc284/abc284_a/main_test.rb
|
50
|
+
```
|
20
51
|
|
21
52
|
## Development
|
22
53
|
|
@@ -26,4 +57,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
26
57
|
|
27
58
|
## Contributing
|
28
59
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/n0h0/acclir.
|
data/acclir.gemspec
CHANGED
@@ -28,6 +28,8 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
+
spec.add_dependency "faraday", "~> 2.7.2"
|
32
|
+
spec.add_dependency "faraday-cookie_jar", "~> 0.0.7"
|
31
33
|
spec.add_dependency "minitest"
|
32
34
|
spec.add_dependency "nokogiri", "~> 1.13.10"
|
33
35
|
spec.add_dependency "thor", "~> 1.2.1"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Acclir
|
4
|
+
module AtCoder
|
5
|
+
# Communication with AtCoder
|
6
|
+
class Connection
|
7
|
+
ATCODER_ROOT_URL = "https://atcoder.jp"
|
8
|
+
COOKIE_JAR_FILE_PATH = "/tmp/acclir_cookie.yml"
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def connection
|
12
|
+
@connection ||= Faraday.new(url: ATCODER_ROOT_URL) do |faraday|
|
13
|
+
faraday.use :cookie_jar, jar: cookie_jar
|
14
|
+
faraday.response :raise_error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(path, &block)
|
19
|
+
connection.get(path, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def post(path, save_cookie: false, &block)
|
23
|
+
FileUtils.rm(COOKIE_JAR_FILE_PATH) if save_cookie
|
24
|
+
|
25
|
+
connection.post(path, &block).tap do
|
26
|
+
save_cookie_jar if save_cookie
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def cookie_jar
|
33
|
+
@cookie_jar ||= if File.exist?(COOKIE_JAR_FILE_PATH)
|
34
|
+
HTTP::CookieJar.new.load(COOKIE_JAR_FILE_PATH)
|
35
|
+
else
|
36
|
+
HTTP::CookieJar.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def save_cookie_jar
|
41
|
+
cookie_jar.save(COOKIE_JAR_FILE_PATH, session: true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "open-uri"
|
4
|
-
|
5
3
|
module Acclir
|
6
4
|
module AtCoder
|
7
5
|
# AtCoder contest
|
8
6
|
class Contest
|
7
|
+
TASKS_PATH_PROC = ->(id) { "/contests/#{id}/tasks" }
|
8
|
+
|
9
9
|
attr_reader :id
|
10
10
|
|
11
11
|
def initialize(id)
|
@@ -18,12 +18,10 @@ module Acclir
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def url
|
22
|
-
@url ||= ATCODER_TASKS_URL_PROC.call(id)
|
23
|
-
end
|
24
|
-
|
25
21
|
def document
|
26
|
-
@document ||= Nokogiri::HTML(
|
22
|
+
@document ||= Nokogiri::HTML(
|
23
|
+
Connection.get(TASKS_PATH_PROC.call(id)).body
|
24
|
+
)
|
27
25
|
end
|
28
26
|
|
29
27
|
def extract_task_ids
|
@@ -31,7 +29,7 @@ module Acclir
|
|
31
29
|
element.attribute("href").content
|
32
30
|
end
|
33
31
|
|
34
|
-
hrefs.uniq.map { |href| href.match(
|
32
|
+
hrefs.uniq.map { |href| href.match(Task::PATH_REGEX_PROC.call(id))&.[](:task) }.compact
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Acclir
|
4
|
+
module AtCoder
|
5
|
+
# AtCoder session
|
6
|
+
class LoginSession
|
7
|
+
PATH = "/login"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def create(username, password)
|
11
|
+
response = Connection.post(PATH, save_cookie: true) do |req|
|
12
|
+
req.headers["Content-Type"] = "application/x-www-form-urlencoded"
|
13
|
+
req.body =
|
14
|
+
URI.encode_www_form({ username: username, password: password, csrf_token: csrf_token })
|
15
|
+
end
|
16
|
+
|
17
|
+
raise LoginFailedError if response.headers["location"] == PATH
|
18
|
+
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def csrf_token
|
25
|
+
Nokogiri::HTML(
|
26
|
+
Connection.get(PATH).body
|
27
|
+
).xpath(
|
28
|
+
"//input[@name='csrf_token']"
|
29
|
+
).first[:value]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/acclir/at_coder/task.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "open-uri"
|
4
|
-
require "nokogiri"
|
5
|
-
|
6
3
|
module Acclir
|
7
4
|
module AtCoder
|
8
5
|
# AtCoder problem
|
@@ -10,6 +7,9 @@ module Acclir
|
|
10
7
|
SAMPLE_INPUT_TITLE = "Sample Input"
|
11
8
|
SAMPLE_OUTPUT_TITLE = "Sample Output"
|
12
9
|
|
10
|
+
PATH_REGEX_PROC = ->(contest_id) { %r{^/contests/#{contest_id}/tasks/(?<task>\w+)$} }
|
11
|
+
PATH_PROC = ->(contest_id, id) { "/contests/#{contest_id}/tasks/#{id}" }
|
12
|
+
|
13
13
|
attr_reader :contest_id, :id
|
14
14
|
|
15
15
|
def initialize(contest_id, id)
|
@@ -23,12 +23,10 @@ module Acclir
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
def url
|
27
|
-
@url ||= ATCODER_TASK_URL_PROC.call(contest_id, id)
|
28
|
-
end
|
29
|
-
|
30
26
|
def document
|
31
|
-
@document ||= Nokogiri::HTML(
|
27
|
+
@document ||= Nokogiri::HTML(
|
28
|
+
Connection.get(PATH_PROC.call(contest_id, id)).body
|
29
|
+
)
|
32
30
|
end
|
33
31
|
|
34
32
|
def extract_samples
|
data/lib/acclir/at_coder.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "faraday"
|
4
|
+
require "faraday-cookie_jar"
|
5
|
+
require "nokogiri"
|
6
|
+
require "fileutils"
|
7
|
+
|
8
|
+
require_relative "./at_coder/connection"
|
9
|
+
require_relative "./at_coder/error"
|
10
|
+
|
11
|
+
require_relative "./at_coder/user"
|
12
|
+
require_relative "./at_coder/login_session"
|
13
|
+
|
3
14
|
require_relative "./at_coder/contest"
|
4
15
|
require_relative "./at_coder/sample"
|
5
16
|
require_relative "./at_coder/task"
|
6
17
|
|
7
18
|
module Acclir
|
19
|
+
# AtCoder
|
8
20
|
module AtCoder
|
9
|
-
ATCODER_URL = "https://atcoder.jp"
|
10
|
-
|
11
|
-
ATCODER_TASKS_PATH_PROC = ->(contest_id) { "/contests/#{contest_id}/tasks" }
|
12
|
-
ATCODER_TASKS_URL_PROC = ->(contest_id) { "#{ATCODER_URL}/contests/#{contest_id}/tasks" }
|
13
|
-
|
14
|
-
ATCODER_TASK_PATH_REGEX_PROC = ->(contest_id) { %r{^/contests/#{contest_id}/tasks/(?<task>\w+)$} }
|
15
|
-
ATCODER_TASK_URL_PROC = ->(contest_id, task_id) { "#{ATCODER_URL}/contests/#{contest_id}/tasks/#{task_id}" }
|
16
21
|
end
|
17
22
|
end
|
data/lib/acclir/cli.rb
CHANGED
@@ -13,6 +13,20 @@ module Acclir
|
|
13
13
|
true
|
14
14
|
end
|
15
15
|
|
16
|
+
desc "login", "Login AtCoder"
|
17
|
+
def login
|
18
|
+
username = ask("Username:")
|
19
|
+
password = ask("Password:", echo: false)
|
20
|
+
|
21
|
+
begin
|
22
|
+
AtCoder::User.login(username, password)
|
23
|
+
|
24
|
+
say "\nLogin succeeded!"
|
25
|
+
rescue AtCoder::LoginFailedError => e
|
26
|
+
say_error "\n#{e.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
16
30
|
register(Command::New, "new", "new CONTEST_ID", "Generate files for the contest")
|
17
31
|
end
|
18
32
|
end
|
data/lib/acclir/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acclir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- n0h0
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.7.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.7.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday-cookie_jar
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.7
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: minitest
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,14 +101,17 @@ files:
|
|
73
101
|
- exe/acclir
|
74
102
|
- lib/acclir.rb
|
75
103
|
- lib/acclir/at_coder.rb
|
104
|
+
- lib/acclir/at_coder/connection.rb
|
76
105
|
- lib/acclir/at_coder/contest.rb
|
106
|
+
- lib/acclir/at_coder/error.rb
|
107
|
+
- lib/acclir/at_coder/login_session.rb
|
77
108
|
- lib/acclir/at_coder/sample.rb
|
78
109
|
- lib/acclir/at_coder/task.rb
|
110
|
+
- lib/acclir/at_coder/user.rb
|
79
111
|
- lib/acclir/cli.rb
|
80
112
|
- lib/acclir/command/new.rb
|
81
113
|
- lib/acclir/templates/new/main_test.rb.tt
|
82
114
|
- lib/acclir/version.rb
|
83
|
-
- sig/acclir.rbs
|
84
115
|
homepage: https://github.com/n0h0/acclir
|
85
116
|
licenses:
|
86
117
|
- MIT
|
data/sig/acclir.rbs
DELETED