otacrawler 0.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 +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/Procfile +1 -0
- data/README.md +39 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/otacrawler +7 -0
- data/bin/setup +8 -0
- data/circle.yml +27 -0
- data/database.yml +13 -0
- data/img/IMG_6837.JPG +0 -0
- data/lib/otacrawler/collector.rb +21 -0
- data/lib/otacrawler/models/author.rb +12 -0
- data/lib/otacrawler/models/comic.rb +14 -0
- data/lib/otacrawler/models/story.rb +9 -0
- data/lib/otacrawler/models/writing.rb +11 -0
- data/lib/otacrawler/robot.rb +13 -0
- data/lib/otacrawler/sites/base.rb +9 -0
- data/lib/otacrawler/sites/tonari_no_yj.rb +142 -0
- data/lib/otacrawler/version.rb +3 -0
- data/lib/otacrawler.rb +28 -0
- data/otacrawler.gemspec +31 -0
- data/otacrawler.sql +139 -0
- data/setup.sql +1 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 473a91699e7860f33690062beb20a24c38f2bff8
|
4
|
+
data.tar.gz: 1924ca2e5e66a1aabf778b03b9afd1439891049b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b6bb304343f9153768a46f293699a186c9449cbec443f8829c6403d84f22f5a012433f0d58118eb5de2637f04fe52d3a3b6cbc6854594e3e909ca53deb45e0d
|
7
|
+
data.tar.gz: 5cc7bc50c145d2573d66ac1f96acde576b447d97447afb8b4ea4f9a1f35bf4d0b4a61725b8ecf96a3b81e009e5dab0a7c91126af0d730742525c07ee3bad1cf2
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 yuta-muramoto
|
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/Procfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bot: bundle exec bin/otacrawler
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Otacrawler [](https://codeclimate.com/github/yuta-muramoto/otacrawler) [](https://circleci.com/gh/yuta-muramoto/otacrawler/tree/test) <img src="img/IMG_6837.JPG" align="right">
|
2
|
+
|
3
|
+
|
4
|
+
Otacrawler is web comic crawler such as the Akihabara otaku.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'otacrawler'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install crawler
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Run robot:
|
25
|
+
|
26
|
+
$ bin/otacrawler
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
If you want to add crawling sites, you add that site to `Otacrawler::Sites`. At that time, you should inherit the site from `Otacrawler::Sites::Base`.
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yuta-muramoto/otacrawler.
|
35
|
+
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "otacrawler"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/otacrawler
ADDED
data/bin/setup
ADDED
data/circle.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
machine:
|
2
|
+
timezone:
|
3
|
+
Asia/Tokyo
|
4
|
+
|
5
|
+
ruby:
|
6
|
+
version:
|
7
|
+
2.3.1
|
8
|
+
|
9
|
+
post:
|
10
|
+
- sudo service postgresql stop
|
11
|
+
|
12
|
+
database:
|
13
|
+
override:
|
14
|
+
- mysql -u root < setup.sql
|
15
|
+
- mysql otacrawler -u root < otacrawler.sql
|
16
|
+
|
17
|
+
dependencies:
|
18
|
+
pre:
|
19
|
+
- gem install bundler --pre
|
20
|
+
|
21
|
+
override:
|
22
|
+
- bundle install:
|
23
|
+
timeout: 180
|
24
|
+
|
25
|
+
test:
|
26
|
+
override:
|
27
|
+
- bundle exec rake test
|
data/database.yml
ADDED
data/img/IMG_6837.JPG
ADDED
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'anemone'
|
2
|
+
|
3
|
+
module Otacrawler
|
4
|
+
class Collector
|
5
|
+
def initialize(url)
|
6
|
+
@url = url
|
7
|
+
end
|
8
|
+
|
9
|
+
def collect(pattern)
|
10
|
+
comics = []
|
11
|
+
Anemone.crawl(@url, depth_limit: 0) do |anemone|
|
12
|
+
anemone.on_every_page do |page|
|
13
|
+
page.doc.xpath(pattern).each do |comic|
|
14
|
+
comics << comic
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
comics
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
module Otacrawler
|
4
|
+
module Models
|
5
|
+
class Comic < ActiveRecord::Base
|
6
|
+
has_many :stories
|
7
|
+
has_many :writing
|
8
|
+
has_many :authors, through: :writing
|
9
|
+
|
10
|
+
validates :url, presence: true, uniqueness: true
|
11
|
+
validates :title, presence: true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require "mem"
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Otacrawler
|
5
|
+
module Sites
|
6
|
+
class TonariNoYJ < Base
|
7
|
+
include Mem
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@url = "http://www.tonarinoyj.jp"
|
11
|
+
@collector = Collector.new(@url)
|
12
|
+
end
|
13
|
+
|
14
|
+
def analyze
|
15
|
+
url_list.each_with_index do |url, i|
|
16
|
+
params = { url: url, title: titles[i] }
|
17
|
+
comic = Models::Comic.new(params)
|
18
|
+
if comic.save # overlapping check
|
19
|
+
create(comic, i)
|
20
|
+
else
|
21
|
+
update(url, i)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def url_list
|
27
|
+
item_body.map do |comic|
|
28
|
+
path = comic.css('a').first.attributes["href"].to_s
|
29
|
+
File.join(@url, path)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
memoize :url_list
|
33
|
+
|
34
|
+
def titles
|
35
|
+
item_body.map do |comic|
|
36
|
+
comic.css('h3').first.inner_text
|
37
|
+
end
|
38
|
+
end
|
39
|
+
memoize :titles
|
40
|
+
|
41
|
+
def authors
|
42
|
+
item_body.map do |comic|
|
43
|
+
authors = comic.css('p').first.inner_text
|
44
|
+
authors.split(/[[:space:]]/)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
memoize :authors
|
48
|
+
|
49
|
+
def image_url_list
|
50
|
+
css = 'figure.home-manga-item-figure'
|
51
|
+
comics = items.map {|item| item.css(css) }
|
52
|
+
comics.map do |comic|
|
53
|
+
path = comic.css('img').first.attributes['src'].to_s
|
54
|
+
File.join(@url, path)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
memoize :image_url_list
|
58
|
+
|
59
|
+
def description(url)
|
60
|
+
collector = Collector.new(url)
|
61
|
+
pattern = "//div[@class='single-story']"
|
62
|
+
comic = collector.collect(pattern)
|
63
|
+
comic.first.css('p').first.inner_text
|
64
|
+
rescue
|
65
|
+
""
|
66
|
+
end
|
67
|
+
|
68
|
+
def stories(url)
|
69
|
+
collector = Collector.new(url)
|
70
|
+
pattern = "//div[@class='single-backnumber']/dl"
|
71
|
+
stories = collector.collect(pattern)
|
72
|
+
result = stories.map do |story|
|
73
|
+
unless story.css('dt').empty?
|
74
|
+
title = story.css('dt').first.inner_text
|
75
|
+
else
|
76
|
+
title = ""
|
77
|
+
end
|
78
|
+
story.css('li').map do |number|
|
79
|
+
path = number.css('a').first.attributes["href"].to_s
|
80
|
+
{
|
81
|
+
url: URI.join(@url, path).to_s,
|
82
|
+
title: title,
|
83
|
+
number: number.inner_text.to_i
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
result.flatten
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def create(comic, i)
|
93
|
+
comic.image_url = image_url_list[i]
|
94
|
+
comic.description = description(comic.url)
|
95
|
+
authors[i].each do |author|
|
96
|
+
comic.authors.build({ name: author })
|
97
|
+
end
|
98
|
+
stories(comic.url).each do |story|
|
99
|
+
comic.stories.build(story)
|
100
|
+
end
|
101
|
+
comic.save
|
102
|
+
end
|
103
|
+
|
104
|
+
def update(url, i)
|
105
|
+
comic = Models::Comic.find_by(url: url)
|
106
|
+
comic.image_url = image_url_list[i]
|
107
|
+
comic.description = description(url)
|
108
|
+
comic.save
|
109
|
+
update_author(url, i)
|
110
|
+
update_story(url, i)
|
111
|
+
end
|
112
|
+
|
113
|
+
def update_author(url, i)
|
114
|
+
comic = Models::Comic.find_by(url: url)
|
115
|
+
authors[i].each do |author|
|
116
|
+
comic.authors.build({ name: author })
|
117
|
+
end
|
118
|
+
comic.save
|
119
|
+
end
|
120
|
+
|
121
|
+
def update_story(url, i)
|
122
|
+
comic = Models::Comic.find_by(url: url)
|
123
|
+
stories(url).each do |story|
|
124
|
+
comic.stories.build(story)
|
125
|
+
end
|
126
|
+
comic.save
|
127
|
+
end
|
128
|
+
|
129
|
+
def items
|
130
|
+
pattern = "//div[@class='home-manga-item-wrapper']"
|
131
|
+
@collector.collect(pattern)
|
132
|
+
end
|
133
|
+
memoize :items
|
134
|
+
|
135
|
+
def item_body
|
136
|
+
css = 'div.home-manga-item-body'
|
137
|
+
items.map {|item| item.css(css) }
|
138
|
+
end
|
139
|
+
memoize :item_body
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/lib/otacrawler.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "yaml"
|
3
|
+
require "mem"
|
4
|
+
require "active_record"
|
5
|
+
|
6
|
+
module Otacrawler
|
7
|
+
config = YAML.load(ERB.new(IO.read("database.yml")).result)
|
8
|
+
ActiveRecord::Base.establish_connection(config["db"]["development"])
|
9
|
+
|
10
|
+
class << self
|
11
|
+
include Mem
|
12
|
+
def sites
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
memoize :sites
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "otacrawler/version"
|
20
|
+
require "otacrawler/collector"
|
21
|
+
require "otacrawler/robot"
|
22
|
+
require "otacrawler/models/comic"
|
23
|
+
require "otacrawler/models/author"
|
24
|
+
require "otacrawler/models/story"
|
25
|
+
require "otacrawler/models/writing"
|
26
|
+
|
27
|
+
require "otacrawler/sites/base"
|
28
|
+
require "otacrawler/sites/tonari_no_yj"
|
data/otacrawler.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'otacrawler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "otacrawler"
|
8
|
+
spec.version = Otacrawler::VERSION
|
9
|
+
spec.authors = ["yuta-muramoto"]
|
10
|
+
spec.email = ["s1513114@u.tsukuba.ac.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{This is web comic crawler.}
|
13
|
+
spec.description = %q{This is web comic crawler that Akihabara otaku.}
|
14
|
+
spec.homepage = "https://github.com/yuta-muramoto/otacrawler.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'mem'
|
23
|
+
spec.add_dependency 'mysql2'
|
24
|
+
spec.add_dependency 'anemone'
|
25
|
+
spec.add_dependency 'activerecord'
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
+
spec.add_development_dependency "minitest-reporters"
|
31
|
+
end
|