ege_parser 1.0.0 → 1.1.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/.coveralls.yml +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +12 -1
- data/README.rdoc +7 -2
- data/VERSION +1 -1
- data/ege_parser.gemspec +7 -5
- data/examples/2.rb +7 -2
- data/lib/ege_parser.rb +66 -66
- data/lib/error.rb +5 -5
- data/lib/pupil.rb +7 -7
- data/spec/ege_parser_spec.rb +53 -52
- data/spec/spec_helper.rb +3 -1
- data/spec/templates/authed_error.html +543 -543
- data/spec/templates/bad_data.html +46 -46
- data/spec/templates/success.html +46 -46
- metadata +17 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c3d88a6d1218841609cc949cdb780de9c477267
|
4
|
+
data.tar.gz: 39b923161b41d0be14e6857929010d628258658f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d373c802c80d53a47f4783673a18f9d8bac3b47da6938da2574920b9bbc3bcef57e1c8f930c8e8ece8ac26aa577cdbb9644599a2437c502f8d1e062a2085401
|
7
|
+
data.tar.gz: e8a8a1e3976bb4f12be6ca26fd5459bb10ceaf7a4d48f7ab749b9ba7f998464ab2835962b0dc1887eb7f2874c762a17ca1d09f2e6c1fd208b66f728a7827b071
|
data/.coveralls.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,6 +3,12 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
addressable (2.3.6)
|
5
5
|
builder (3.2.2)
|
6
|
+
coveralls (0.7.0)
|
7
|
+
multi_json (~> 1.3)
|
8
|
+
rest-client
|
9
|
+
simplecov (>= 0.7)
|
10
|
+
term-ansicolor
|
11
|
+
thor
|
6
12
|
crack (0.4.2)
|
7
13
|
safe_yaml (~> 1.0.0)
|
8
14
|
descendants_tracker (0.0.4)
|
@@ -72,6 +78,8 @@ GEM
|
|
72
78
|
rake (10.3.2)
|
73
79
|
rdoc (3.12.2)
|
74
80
|
json (~> 1.4)
|
81
|
+
rest-client (1.6.7)
|
82
|
+
mime-types (>= 1.16)
|
75
83
|
rspec (2.8.0)
|
76
84
|
rspec-core (~> 2.8.0)
|
77
85
|
rspec-expectations (~> 2.8.0)
|
@@ -86,8 +94,11 @@ GEM
|
|
86
94
|
multi_json
|
87
95
|
simplecov-html (~> 0.8.0)
|
88
96
|
simplecov-html (0.8.0)
|
97
|
+
term-ansicolor (1.3.0)
|
98
|
+
tins (~> 1.0)
|
89
99
|
thor (0.19.1)
|
90
100
|
thread_safe (0.3.4)
|
101
|
+
tins (1.3.0)
|
91
102
|
unf (0.1.4)
|
92
103
|
unf_ext
|
93
104
|
unf_ext (0.0.6)
|
@@ -101,11 +112,11 @@ PLATFORMS
|
|
101
112
|
|
102
113
|
DEPENDENCIES
|
103
114
|
bundler (~> 1.0)
|
115
|
+
coveralls
|
104
116
|
foreman
|
105
117
|
jeweler (~> 2.0.1)
|
106
118
|
mechanize
|
107
119
|
nokogiri
|
108
120
|
rdoc (~> 3.12)
|
109
121
|
rspec (~> 2.8.0)
|
110
|
-
simplecov
|
111
122
|
webmock
|
data/README.rdoc
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
= ege_parser
|
1
|
+
= ege_parser {<img src="https://coveralls.io/repos/manyrus/ege_gem/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/manyrus/ege_gem] {<img src="https://travis-ci.org/manyrus/ege_gem.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/manyrus/ege_gem]
|
2
2
|
|
3
|
-
|
3
|
+
See {example}[https://github.com/manyrus/ege_gem/blob/master/examples/2.rb]
|
4
4
|
|
5
|
+
== Installing
|
6
|
+
Simply add to your Gemfile this code:
|
7
|
+
gem 'ege_parser'
|
8
|
+
Or exec from console:
|
9
|
+
$ gem install ege_parser
|
5
10
|
== Contributing to ege_parser
|
6
11
|
|
7
12
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/ege_parser.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: ege_parser 1.
|
5
|
+
# stub: ege_parser 1.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "ege_parser"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -19,8 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
"README.rdoc"
|
20
20
|
]
|
21
21
|
s.files = [
|
22
|
+
".coveralls.yml",
|
22
23
|
".document",
|
23
24
|
".rspec",
|
25
|
+
".travis.yml",
|
24
26
|
"Gemfile",
|
25
27
|
"Gemfile.lock",
|
26
28
|
"LICENSE.txt",
|
@@ -48,6 +50,7 @@ Gem::Specification.new do |s|
|
|
48
50
|
s.specification_version = 4
|
49
51
|
|
50
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_runtime_dependency(%q<coveralls>, [">= 0"])
|
51
54
|
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
52
55
|
s.add_runtime_dependency(%q<mechanize>, [">= 0"])
|
53
56
|
s.add_runtime_dependency(%q<foreman>, [">= 0"])
|
@@ -55,9 +58,9 @@ Gem::Specification.new do |s|
|
|
55
58
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
56
59
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
57
60
|
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
58
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
59
61
|
s.add_development_dependency(%q<webmock>, [">= 0"])
|
60
62
|
else
|
63
|
+
s.add_dependency(%q<coveralls>, [">= 0"])
|
61
64
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
62
65
|
s.add_dependency(%q<mechanize>, [">= 0"])
|
63
66
|
s.add_dependency(%q<foreman>, [">= 0"])
|
@@ -65,10 +68,10 @@ Gem::Specification.new do |s|
|
|
65
68
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
66
69
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
67
70
|
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
68
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
69
71
|
s.add_dependency(%q<webmock>, [">= 0"])
|
70
72
|
end
|
71
73
|
else
|
74
|
+
s.add_dependency(%q<coveralls>, [">= 0"])
|
72
75
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
73
76
|
s.add_dependency(%q<mechanize>, [">= 0"])
|
74
77
|
s.add_dependency(%q<foreman>, [">= 0"])
|
@@ -76,7 +79,6 @@ Gem::Specification.new do |s|
|
|
76
79
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
77
80
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
78
81
|
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
79
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
80
82
|
s.add_dependency(%q<webmock>, [">= 0"])
|
81
83
|
end
|
82
84
|
end
|
data/examples/2.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
require 'ege_parser'
|
2
|
+
|
2
3
|
pupil = EgeParser::Pupil.new
|
3
4
|
|
4
5
|
pupil.name = 'Никитос'
|
@@ -8,4 +9,8 @@ pupil.passport = '453312'
|
|
8
9
|
pupil.region = '45'
|
9
10
|
|
10
11
|
ege_parser = EgeParser::Parser.new
|
11
|
-
|
12
|
+
begin
|
13
|
+
p ege_parser.get_subjects pupil #output as {'subject'=>'status', 'subject#2'=>'status2'}
|
14
|
+
rescue EgeParser::AuthError #see all errors in error.rb
|
15
|
+
p 'Auth error('
|
16
|
+
end
|
data/lib/ege_parser.rb
CHANGED
@@ -8,70 +8,70 @@ require_relative 'pupil.rb'
|
|
8
8
|
|
9
9
|
module EgeParser
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
11
|
+
class Parser
|
12
|
+
|
13
|
+
attr_writer :auth_agent
|
14
|
+
|
15
|
+
def auth_agent
|
16
|
+
@auth_agent ||= Mechanize.new
|
17
|
+
@auth_agent.open_timeout=180
|
18
|
+
@auth_agent.read_timeout=180
|
19
|
+
@auth_agent
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_subjects pupil
|
23
|
+
page = auth_agent.post('http://check.ege.edu.ru/ru/index.php', {
|
24
|
+
name: pupil.name,
|
25
|
+
surname: pupil.surname,
|
26
|
+
patronymic: pupil.patronymic,
|
27
|
+
doc_number: pupil.passport,
|
28
|
+
region: pupil.region,
|
29
|
+
generate_captcha_val => ''
|
30
|
+
})
|
31
|
+
|
32
|
+
generate_subjects page
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def generate_captcha_val
|
38
|
+
captcha_key = '-a-UHS2Wj8Cy8W4QB4cpZ8y_6XZNUWU'
|
39
|
+
page = auth_agent.post('http://check.ege.edu.ru/common/Qaptcha.jquery.php', {
|
40
|
+
action:'qaptcha',
|
41
|
+
qaptcha_key:captcha_key
|
42
|
+
})
|
43
|
+
raise EgeParser::CaptchaError if JSON.parse(page.body)['error']
|
44
|
+
captcha_key
|
45
|
+
end
|
46
|
+
|
47
|
+
def generate_subjects page
|
48
|
+
Hash[find_elements(2, page).zip find_elements(5, page)]
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_elements row, page
|
52
|
+
result = []
|
53
|
+
page.search("//table[contains(@class, 'appil_resultat')]/tbody/tr/td[#{row}]").to_a.map{|el|
|
54
|
+
parsed = el_to_s(el)
|
55
|
+
result << parsed if parsed != nil|| parsed != ''
|
56
|
+
}
|
57
|
+
|
58
|
+
check_for_errors page
|
59
|
+
|
60
|
+
raise EgeParser::BadDataError if result.any?{|k| k.empty?} || result.empty?
|
61
|
+
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
def check_for_errors page
|
66
|
+
service_error = el_to_s(page.search('//h2'))
|
67
|
+
raise EgeParser::ServiceError.new(service_error) unless service_error.empty?
|
68
|
+
|
69
|
+
auth_error = el_to_s(page.search('//div[@id="show_div2"]/form'))
|
70
|
+
raise EgeParser::AuthError.new unless auth_error.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
def el_to_s el
|
74
|
+
el.to_s.gsub(/<\/?[^>]+>/, '').gsub(/\n|\t/,'').strip
|
75
|
+
end
|
76
|
+
end
|
77
77
|
end
|
data/lib/error.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module EgeParser
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class AuthError < StandardError; end
|
3
|
+
class ParserError < StandardError; end
|
4
|
+
class BadDataError < StandardError; end
|
5
|
+
class ServiceError < StandardError; end
|
6
|
+
class CaptchaError < StandardError; end
|
7
7
|
end
|
data/lib/pupil.rb
CHANGED
data/spec/ege_parser_spec.rb
CHANGED
@@ -1,70 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
3
|
|
3
4
|
describe EgeParser::Parser, :fast do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
let(:pupil){
|
6
|
+
pupil = EgeParser::Pupil.new
|
7
|
+
pupil.name = 'Сер'
|
8
|
+
pupil.surname = 'ПоЛяков'
|
9
|
+
pupil.patronymic = 'Сергеевич'
|
10
|
+
pupil.passport = '342412'
|
11
|
+
pupil.region = '30'
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
pupil
|
14
|
+
}
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def stub_captcha(is_error = false)
|
17
|
+
stub_request(:post, 'http://check.ege.edu.ru/common/Qaptcha.jquery.php').to_return(body:{error:is_error}.to_json)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def stub_result file_name
|
21
|
+
stub_request(:post, "http://check.ege.edu.ru/ru/index.php")
|
22
|
+
.to_return(
|
23
|
+
:status => 200,
|
24
|
+
:body => File.read(File.dirname(__FILE__) + "/templates/#{file_name}.html"),
|
25
|
+
:headers => {'Content-Type'=>'text/html'}
|
26
|
+
)
|
27
|
+
end
|
27
28
|
|
28
29
|
describe '#get_subjects' do
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
context 'when bad captcha' do
|
31
|
+
it 'throw EgeParser::CaptchaError' do
|
32
|
+
stub_captcha(true)
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
expect{subject.get_subjects pupil}.to raise_error(EgeParser::CaptchaError)
|
35
|
+
end
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
context 'when not authed' do
|
39
|
+
it 'throw EgeParser::AuthError' do
|
40
|
+
stub_captcha
|
41
|
+
stub_result 'authed_error'
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
expect{subject.get_subjects pupil}.to raise_error(EgeParser::AuthError)
|
44
|
+
end
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
context 'when some subject is empty' do
|
48
|
+
it 'throw EgeParser::ParserError' do
|
49
|
+
stub_captcha
|
50
|
+
stub_result 'bad_data'
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
expect{p subject.get_subjects pupil}.to raise_error(EgeParser::BadDataError)
|
53
|
+
end
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
context 'all ok' do
|
57
|
+
it 'parse all data and get result' do
|
58
|
+
stub_captcha
|
59
|
+
stub_result 'success'
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
subject.get_subjects(pupil).should ==
|
62
|
+
{'Русский язык' => 'Нет результата (обработка)',
|
63
|
+
'Математика' => 'Экзамен не проходил',
|
64
|
+
'Физика' => 'Экзамен не проходил',
|
65
|
+
'Информатика и ИКТ' => 'Экзамен не проходил'}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
68
69
|
end
|
69
70
|
|
70
71
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
require 'webmock/rspec'
|
3
|
+
require 'coveralls'
|
3
4
|
|
5
|
+
Coveralls.wear!
|
4
6
|
module SimpleCov::Configuration
|
5
7
|
def clean_filters
|
6
8
|
@filters = []
|
@@ -26,5 +28,5 @@ require 'ege_parser'
|
|
26
28
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
27
29
|
|
28
30
|
RSpec.configure do |c|
|
29
|
-
|
31
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
30
32
|
end
|