dmm-crawler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.rubocop.yml +21 -0
- data/.travis.yml +15 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +84 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +11 -0
- data/dmm-crawler.gemspec +27 -0
- data/lib/dmm-crawler.rb +8 -0
- data/lib/dmm-crawler/agent.rb +11 -0
- data/lib/dmm-crawler/ranking.rb +47 -0
- data/lib/dmm-crawler/version.rb +3 -0
- data/spec/dmm-crawler/ranking_spec.rb +25 -0
- data/spec/spec_helper.rb +8 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5df41735d4f8eedf776285760e2cc02e4bcc7c39
|
4
|
+
data.tar.gz: 85f963c4432c166a3d5b9896099babaffc9cd407
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79819ff75becdf9790590491d15afc27f641c2c61b68c9a8f5049fc971121eebc6b4894d114ecec719d62497f8eb5cd6e45d7260d1b31736d19b63f7cdb3f1d8
|
7
|
+
data.tar.gz: bfe581c5bff9f8a69910fac9821ff86e9822df122a409cdae86199229db302ccc4885d337479ac559dd9db2d53dc97f0d9c84b57cd08ea0e8500033c2845da70
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
LineLength:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Metrics/AbcSize:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
CyclomaticComplexity:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Max: 12
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/FileName:
|
20
|
+
Exclude:
|
21
|
+
- lib/dmm-crawler.rb
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dmm-crawler (0.0.1)
|
5
|
+
mechanize
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.3.0)
|
11
|
+
coderay (1.1.1)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
domain_name (0.5.20170223)
|
14
|
+
unf (>= 0.0.5, < 1.0.0)
|
15
|
+
http-cookie (1.0.3)
|
16
|
+
domain_name (~> 0.5)
|
17
|
+
mechanize (2.7.5)
|
18
|
+
domain_name (~> 0.5, >= 0.5.1)
|
19
|
+
http-cookie (~> 1.0)
|
20
|
+
mime-types (>= 1.17.2)
|
21
|
+
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
22
|
+
net-http-persistent (~> 2.5, >= 2.5.2)
|
23
|
+
nokogiri (~> 1.6)
|
24
|
+
ntlm-http (~> 0.1, >= 0.1.1)
|
25
|
+
webrobots (>= 0.0.9, < 0.2)
|
26
|
+
method_source (0.8.2)
|
27
|
+
mime-types (3.1)
|
28
|
+
mime-types-data (~> 3.2015)
|
29
|
+
mime-types-data (3.2016.0521)
|
30
|
+
mini_portile2 (2.1.0)
|
31
|
+
net-http-digest_auth (1.4.1)
|
32
|
+
net-http-persistent (2.9.4)
|
33
|
+
nokogiri (1.7.0.1)
|
34
|
+
mini_portile2 (~> 2.1.0)
|
35
|
+
ntlm-http (0.1.1)
|
36
|
+
parser (2.4.0.0)
|
37
|
+
ast (~> 2.2)
|
38
|
+
powerpack (0.1.1)
|
39
|
+
pry (0.10.4)
|
40
|
+
coderay (~> 1.1.0)
|
41
|
+
method_source (~> 0.8.1)
|
42
|
+
slop (~> 3.4)
|
43
|
+
rainbow (2.2.1)
|
44
|
+
rake (10.5.0)
|
45
|
+
rspec (3.5.0)
|
46
|
+
rspec-core (~> 3.5.0)
|
47
|
+
rspec-expectations (~> 3.5.0)
|
48
|
+
rspec-mocks (~> 3.5.0)
|
49
|
+
rspec-core (3.5.4)
|
50
|
+
rspec-support (~> 3.5.0)
|
51
|
+
rspec-expectations (3.5.0)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.5.0)
|
54
|
+
rspec-mocks (3.5.0)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.5.0)
|
57
|
+
rspec-support (3.5.0)
|
58
|
+
rubocop (0.47.1)
|
59
|
+
parser (>= 2.3.3.1, < 3.0)
|
60
|
+
powerpack (~> 0.1)
|
61
|
+
rainbow (>= 1.99.1, < 3.0)
|
62
|
+
ruby-progressbar (~> 1.7)
|
63
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
64
|
+
ruby-progressbar (1.8.1)
|
65
|
+
slop (3.6.0)
|
66
|
+
unf (0.1.4)
|
67
|
+
unf_ext
|
68
|
+
unf_ext (0.0.7.2)
|
69
|
+
unicode-display_width (1.1.3)
|
70
|
+
webrobots (0.1.2)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
ruby
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
bundler (~> 1.14)
|
77
|
+
dmm-crawler!
|
78
|
+
pry (= 0.10.4)
|
79
|
+
rake (~> 10.0)
|
80
|
+
rspec (= 3.5.0)
|
81
|
+
rubocop (~> 0.47)
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
1.14.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Satoshi Ohmori
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
gem_helper = Bundler::GemHelper.new
|
7
|
+
|
8
|
+
desc "Create tag #{gem_helper.send(:version_tag)}"
|
9
|
+
task :tag do
|
10
|
+
gem_helper.send(:tag_version) unless gem_helper.send(:already_tagged?)
|
11
|
+
end
|
data/dmm-crawler.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'dmm-crawler/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'dmm-crawler'
|
7
|
+
spec.version = DMMCrawler::VERSION
|
8
|
+
spec.authors = ['Satoshi Ohmori']
|
9
|
+
spec.email = ['sachin21dev@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = "Show DMM and DMM.R18's crawled data"
|
12
|
+
spec.description = "Show DMM and DMM.R18's crawled data. e.g. ranking"
|
13
|
+
spec.homepage = 'https://github.com/sachin21/dmm-crawler'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'mechanize'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rubocop', '~> 0.47'
|
25
|
+
spec.add_development_dependency 'pry', '0.10.4'
|
26
|
+
spec.add_development_dependency 'rspec', '3.5.0'
|
27
|
+
end
|
data/lib/dmm-crawler.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module DMMCrawler
|
2
|
+
class Ranking
|
3
|
+
BASE_URL = 'http://www.dmm.co.jp'.freeze
|
4
|
+
COLORS = %w(7acc28 9dcc28 cc2828 cc6e28 28a9cc 3428cc cc28b4 c0cc28 2886cc 28cca9).map { |hex| "##{hex}" }.freeze
|
5
|
+
|
6
|
+
def initialize(arguments)
|
7
|
+
@term = discriminate_term(arguments[:term])
|
8
|
+
@submedia = discriminate_submedia(arguments[:submedia])
|
9
|
+
@url = "#{BASE_URL}/dc/doujin/-/ranking-all/=/sort=popular/submedia=#{@submedia}/term=#{@term}"
|
10
|
+
@agent = Agent.new.agent
|
11
|
+
end
|
12
|
+
|
13
|
+
def books
|
14
|
+
books = page.search('.rank-rankListItem.fn-setPurchaseChange').map do |element|
|
15
|
+
[
|
16
|
+
element.search('.rank-name').first.text.strip,
|
17
|
+
element.search('img').last.attributes['src'].value,
|
18
|
+
"#{BASE_URL}#{element.search('.rank-name').first.search('a').first.attributes.first[1].value}"
|
19
|
+
]
|
20
|
+
end
|
21
|
+
books.take(10).zip(COLORS).map.with_index(1) { |((title, image, url), color), rank| { title: "#{rank}位: #{title}", title_link: url, image_url: image, color: color } }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def credentials
|
27
|
+
{
|
28
|
+
api_id: ENV['API_ID'],
|
29
|
+
affiliate_id: ENV['AFFILIATE_ID']
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def page
|
34
|
+
@agent.get(@url)
|
35
|
+
end
|
36
|
+
|
37
|
+
def discriminate_term(term)
|
38
|
+
return term if %w(24 weekly monthly total).include?(term)
|
39
|
+
raise TypeError
|
40
|
+
end
|
41
|
+
|
42
|
+
def discriminate_submedia(submedia)
|
43
|
+
return submedia if %w(all weekly cg game voice).include?(submedia)
|
44
|
+
raise TypeError
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe DMMCrawler::Ranking do
|
2
|
+
let(:attachments) { described_class.new(arguments).books }
|
3
|
+
|
4
|
+
let(:submedia) { 'cg' }
|
5
|
+
let(:arguments) { { submedia: submedia, term: term } }
|
6
|
+
|
7
|
+
describe '#books' do
|
8
|
+
context 'with 24 argument' do
|
9
|
+
subject { attachments }
|
10
|
+
|
11
|
+
let(:term) { '24' }
|
12
|
+
|
13
|
+
it { is_expected.not_to be_empty }
|
14
|
+
it { is_expected.to all(include(:title, :title_link, :image_url, :color)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with not registered argument' do
|
18
|
+
subject { -> { attachments } }
|
19
|
+
|
20
|
+
let(:term) { 'hoge' }
|
21
|
+
|
22
|
+
it { is_expected.to raise_error(TypeError) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dmm-crawler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Satoshi Ohmori
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.47'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.47'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.5.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.5.0
|
97
|
+
description: Show DMM and DMM.R18's crawled data. e.g. ranking
|
98
|
+
email:
|
99
|
+
- sachin21dev@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- Rakefile
|
112
|
+
- dmm-crawler.gemspec
|
113
|
+
- lib/dmm-crawler.rb
|
114
|
+
- lib/dmm-crawler/agent.rb
|
115
|
+
- lib/dmm-crawler/ranking.rb
|
116
|
+
- lib/dmm-crawler/version.rb
|
117
|
+
- spec/dmm-crawler/ranking_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: https://github.com/sachin21/dmm-crawler
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.6.11
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Show DMM and DMM.R18's crawled data
|
143
|
+
test_files: []
|