ojsubmitter 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5e09460f877c47644d23150a3c3479d03fea45b
4
- data.tar.gz: 5e2424eb3262f1c2be86470dfc861ae115244665
3
+ metadata.gz: 4c31db1fd2585d4ed4427c155dfa5aa995773c74
4
+ data.tar.gz: 9399f3e6179459f81314f50205224afbc94ce3c7
5
5
  SHA512:
6
- metadata.gz: 5de9ad732e98acb2310b945d0d4315ec6c995669bc752a0745560c56411aae8f0bc08846db46d294d5477f87d6b037c7253255c8455faae984272e7a05681619
7
- data.tar.gz: 5ee1531964bbd18240024d6b2bfa0312d7294844afd7a2f09ae79af862b47ce10c759fd8ef030f595f4754d83d7068053c890908fe52871d620bd28db2bb1de2
6
+ metadata.gz: a602d458dd531e674b253579a01c55aff2641b4a73f838c88e6222686f9c52e5856913af81378f29b9d0e2d0637fad32d97a423e314db1927a31d12c628479c7
7
+ data.tar.gz: cee4338c534b173fc6b3e90e46eda0e4a08279cd246e9be74f55a49aa05e7d2259af35cbf4cc6297582cfdd73405cb21a6ca7e2201ccf663212479c465661e74
data/README.md CHANGED
@@ -12,6 +12,7 @@ Submit a source code to the online judge from CLI.
12
12
  - [AIZU ONLINE JUDGE](http://judge.u-aizu.ac.jp)
13
13
  - [PKU JudgeOnline](http://poj.org)
14
14
  - [Sphere online judge](http://www.spoj.com)
15
+ - [Codeforces](http://codeforces.com)
15
16
 
16
17
  You can also get this list from `ojsubmitter list` command.
17
18
 
data/lib/ojsubmitter.rb CHANGED
@@ -4,6 +4,7 @@ require "ojsubmitter/util"
4
4
  require 'ojsubmitter/judge/aoj'
5
5
  require 'ojsubmitter/judge/poj'
6
6
  require 'ojsubmitter/judge/spoj'
7
+ require 'ojsubmitter/judge/codeforces'
7
8
 
8
9
  module OJS
9
10
  ROOT_DIR = File.expand_path(File.join(__FILE__, '..', '..'))
@@ -4,6 +4,8 @@ require 'yaml'
4
4
 
5
5
  module OJS
6
6
  class CLI < Thor
7
+ class UnknownJudgeError < StandardError; end
8
+
7
9
  default_command :submit
8
10
 
9
11
  def initialize(*)
@@ -17,36 +19,29 @@ module OJS
17
19
 
18
20
  desc "submit", "Submit your source code."
19
21
  option :judge,
20
- :aliases => "-j",
21
- :desc => "Specify a target judge."
22
+ aliases: "-j",
23
+ desc: "Specify a target judge."
22
24
  option :file,
23
- :aliases => "-f",
24
- :desc => "Specify your source file to submit."
25
+ aliases: "-f",
26
+ desc: "Specify your source file to submit."
25
27
  option :user,
26
- :aliases => "-u",
27
- :desc => "Specify your user_name."
28
+ aliases: "-u",
29
+ desc: "Specify your user_name."
28
30
  option :password,
29
- :aliases => "-p",
30
- :desc => "Specify your password."
31
+ aliases: "-p",
32
+ desc: "Specify your password."
31
33
  option :language,
32
- :aliases => "-l",
33
- :desc => "Specify a programming language."
34
+ aliases: "-l",
35
+ desc: "Specify a programming language."
34
36
  option :nostatus,
35
- :aliases => "-n",
36
- :type => :boolean,
37
- :desc => "Don't show status page after submitting."
37
+ aliases: "-n",
38
+ type: :boolean,
39
+ desc: "Don't show status page after submitting."
38
40
  def submit
39
41
  @config = set_options_from_config_file(options.to_h)
40
- case @config['judge'].to_s.downcase
41
- when 'aoj'
42
- OJS::AOJ.submit @config
43
- when 'poj'
44
- OJS::POJ.submit @config
45
- when 'spoj'
46
- OJS::SPOJ.submit @config
47
- else
48
- list
49
- end
42
+ judge_class.submit @config
43
+ rescue UnknownJudgeError => err
44
+ list
50
45
  end
51
46
 
52
47
  SAMPLE_CONFIG_PATH = File.join(OJS::ROOT_DIR, '.ojsconf.yml.sample')
@@ -73,5 +68,16 @@ module OJS
73
68
  end
74
69
  config
75
70
  end
71
+
72
+ def judge_class
73
+ case @config['judge'].to_s.downcase
74
+ when 'aoj', 'poj', 'spoj'
75
+ OJS.const_get @config['judge'].upcase
76
+ when 'codeforces', 'cf'
77
+ OJS::Codeforces
78
+ else
79
+ raise UnknownJudgeError
80
+ end
81
+ end
76
82
  end
77
83
  end
@@ -8,7 +8,7 @@ module OJS
8
8
 
9
9
  class << self
10
10
  def valid_judges
11
- %w[AOJ POJ SPOJ]
11
+ %w[AOJ POJ SPOJ Codeforces]
12
12
  end
13
13
 
14
14
  def login
@@ -20,11 +20,11 @@ module OJS
20
20
  def post
21
21
  hclient.post(
22
22
  'http://judge.u-aizu.ac.jp/onlinejudge/servlet/Submit',
23
- { :userID => user,
24
- :password => password,
25
- :problemNO => problem_id,
26
- :language => language,
27
- :sourceCode => code }
23
+ { userID: user,
24
+ password: password,
25
+ problemNO: problem_id,
26
+ language: language,
27
+ sourceCode: code }
28
28
  )
29
29
  end
30
30
 
@@ -0,0 +1,99 @@
1
+ require 'ojsubmitter/judge'
2
+ require 'nokogiri'
3
+
4
+ module OJS
5
+ class Codeforces < Judge
6
+ class << self
7
+ LANGUAGE_ID = {
8
+ 'gcc' => '10',
9
+ 'g++' => '43',
10
+ 'g++11' => '1',
11
+ 'msc++' => '2',
12
+ 'c#' => '9',
13
+ 'msc#' => '29',
14
+ 'd' => '28',
15
+ 'go' => '32',
16
+ 'haskell' => '12',
17
+ 'java7' => '23',
18
+ 'java' => '36',
19
+ 'ocaml' => '19',
20
+ 'delphi' => '3',
21
+ 'pascal' => '4',
22
+ 'perl' => '13',
23
+ 'php' => '6',
24
+ 'python' => '7',
25
+ 'python3' => '31',
26
+ 'pypy' => '40',
27
+ 'pypy3' => '41',
28
+ 'ruby' => '8',
29
+ 'scala' => '20',
30
+ 'javascript' => '34',
31
+ 'activetcl' => '14',
32
+ 'io' => '15',
33
+ 'pike' => '17',
34
+ 'befunge' => '18',
35
+ 'cobol' => '22',
36
+ 'factor' => '25',
37
+ 'secret' => '26',
38
+ 'roco' => '27',
39
+ 'ada' => '33',
40
+ 'mysterious' => '28',
41
+ 'false' => '39',
42
+ 'picat' => '44',
43
+ }
44
+
45
+ def login
46
+ res = hclient.post(
47
+ 'http://codeforces.com/enter',
48
+ { handle: user,
49
+ password: password,
50
+ action: 'enter',
51
+ ftaa: '',
52
+ bfaa: '',
53
+ csrf_token: csrf_token,
54
+ }
55
+ )
56
+ raise Judge::LoginFailedError if res.body =~ /(Invalid handle or password)|(Fill in the form to login into Codeforces.)/
57
+ Logger.info "Logged in successfully."
58
+ end
59
+
60
+ def post
61
+ res = hclient.post(
62
+ 'http://codeforces.com/problemset/submit',
63
+ { submittedProblemCode: problem_id,
64
+ programTypeId: language,
65
+ source: code,
66
+ csrf_token: csrf_token,
67
+ action: 'submitSolutionFormSubmitted',
68
+ }
69
+ )
70
+ end
71
+
72
+ def status_url
73
+ "http://codeforces.com/submissions/#{user}"
74
+ end
75
+
76
+ def language
77
+ LANGUAGE_ID[@config['language'].to_s.downcase]
78
+ end
79
+
80
+ def problem_id
81
+ unless @config['problem_id']
82
+ @config['problem_id'] = File.basename(file).split('.')[0]
83
+ unless @config['problem_id'] =~ /\d+/
84
+ @config['problem_id'] = Dir.pwd.split('/').last + @config['problem_id']
85
+ end
86
+ end
87
+ @config['problem_id'].to_s.upcase
88
+ end
89
+
90
+ def csrf_token
91
+ unless @csrf_token
92
+ res = hclient.get('http://codeforces.com')
93
+ @csrf_token = Nokogiri::HTML.parse(res.body).xpath('/html/head/meta[@name="X-Csrf-Token"]/@content').to_s
94
+ end
95
+ @csrf_token
96
+ end
97
+ end
98
+ end
99
+ end
@@ -16,8 +16,8 @@ module OJS
16
16
  def login
17
17
  res = hclient.post(
18
18
  'http://poj.org/login',
19
- { :user_id1 => user,
20
- :password1 => password }
19
+ { user_id1: user,
20
+ password1: password }
21
21
  )
22
22
  raise Judge::LoginFailedError if res.body =~ /Login failed!/
23
23
  Logger.info "Logged in successfully."
@@ -26,10 +26,10 @@ module OJS
26
26
  def post
27
27
  res = hclient.post(
28
28
  'http://poj.org/submit',
29
- { :problem_id => problem_id,
30
- :language => language,
31
- :source => code,
32
- :encoded => 'UTF-8',
29
+ { problem_id: problem_id,
30
+ language: language,
31
+ source: code,
32
+ encoded: 'UTF-8',
33
33
  }
34
34
  )
35
35
  raise Judge::SubmissionError if res.body =~ /(Error Occurred)|(Error report)/
@@ -63,8 +63,8 @@ module OJS
63
63
  def login
64
64
  res = hclient.post(
65
65
  'http://www.spoj.com/login/',
66
- { :login_user => user,
67
- :password => password }
66
+ { login_user: user,
67
+ password: password }
68
68
  )
69
69
  raise Judge::LoginFailedError if res.body =~ /Authentication failed!/
70
70
  Logger.info "Logged in successfully."
@@ -73,9 +73,9 @@ module OJS
73
73
  def post
74
74
  res = hclient.post(
75
75
  'http://www.spoj.com/submit/complete/',
76
- { :problemcode => problem_id,
77
- :lang => language,
78
- :file => code }
76
+ { problemcode: problem_id,
77
+ lang: language,
78
+ file: code }
79
79
  )
80
80
  raise Judge::SubmissionError if res.body =~ /Error/
81
81
  end
@@ -1,3 +1,3 @@
1
1
  module OJS
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/ojsubmitter.gemspec CHANGED
@@ -18,13 +18,18 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = ["ojsubmitter"]
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = '>= 2.0.0'
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.11"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
23
25
  spec.add_development_dependency "rspec", "~> 3.0"
24
26
  spec.add_development_dependency "simplecov", "~> 0.11.0"
25
27
  spec.add_development_dependency "coveralls", "~> 0.8.0"
26
28
  spec.add_development_dependency "fakefs", "~> 0.8.0"
29
+ spec.add_development_dependency "vcr", "~> 3.0.0"
30
+ spec.add_development_dependency "webmock", "~> 1.22.0"
27
31
 
28
32
  spec.add_dependency 'httpclient', '~> 2.7.0'
29
33
  spec.add_dependency 'thor', '~> 0.19.0'
34
+ spec.add_dependency 'nokogiri', '~> 1.6.8.rc3'
30
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ojsubmitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hadrori
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.8.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.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.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.22.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.22.0
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: httpclient
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +150,20 @@ dependencies:
122
150
  - - "~>"
123
151
  - !ruby/object:Gem::Version
124
152
  version: 0.19.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: nokogiri
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.6.8.rc3
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 1.6.8.rc3
125
167
  description:
126
168
  email:
127
169
  - hadrori.hs@gmail.com
@@ -146,6 +188,7 @@ files:
146
188
  - lib/ojsubmitter/cli.rb
147
189
  - lib/ojsubmitter/judge.rb
148
190
  - lib/ojsubmitter/judge/aoj.rb
191
+ - lib/ojsubmitter/judge/codeforces.rb
149
192
  - lib/ojsubmitter/judge/poj.rb
150
193
  - lib/ojsubmitter/judge/spoj.rb
151
194
  - lib/ojsubmitter/logger.rb
@@ -164,7 +207,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
207
  requirements:
165
208
  - - ">="
166
209
  - !ruby/object:Gem::Version
167
- version: '0'
210
+ version: 2.0.0
168
211
  required_rubygems_version: !ruby/object:Gem::Requirement
169
212
  requirements:
170
213
  - - ">="