Ruby4Misawa 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.rdoc +26 -0
- data/Ruby4Misawa-0.1.gemspec +13 -0
- data/Ruby4Misawa.rb +174 -0
- metadata +59 -0
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= Ruby4Misawa
|
2
|
+
|
3
|
+
== これはなにか
|
4
|
+
|
5
|
+
- 地獄のミサワの画像を取ってくるやつ
|
6
|
+
- 画像はURLで出力するか、保存するかを選ぶ
|
7
|
+
|
8
|
+
== インストール
|
9
|
+
|
10
|
+
gem install Ruby4Misawa でおk
|
11
|
+
|
12
|
+
== つかいかた
|
13
|
+
|
14
|
+
ruby Ruby4Misawa.rb [オプション] [値]
|
15
|
+
|
16
|
+
[-t [uri, save]] uriは画像のURIを出力、saveは保存しまくる。permission関係でこける可能性はありけり。
|
17
|
+
[-c [カテゴリ名]] ルシフェル や バイトリーダーのように指定。一つしか指定できないので注意。
|
18
|
+
[-p [対象ページ]] 1 や 0のような数値か、0..5のようにRange形式で指定
|
19
|
+
|
20
|
+
--type, --category, --pageでも可
|
21
|
+
|
22
|
+
ちなみに何も指定しないと地獄のミサワのトップページにあるミサワ画像(と思われるもの)を取ってくる
|
23
|
+
|
24
|
+
== 備考
|
25
|
+
|
26
|
+
なんかおかしかったらすいません
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do | spec |
|
4
|
+
spec.name = 'Ruby4Misawa'
|
5
|
+
spec.version = '0.1'
|
6
|
+
spec.summary = 'スクレイピングライブラリ for 地獄のミサワ'
|
7
|
+
spec.description = '地獄のミサワブログにあるURLがとれたり、そのまま画像を保存したりできます。'
|
8
|
+
spec.homepage = 'https://github.com/namusyaka/Ruby4Misawa'
|
9
|
+
spec.author = 'namusyaka'
|
10
|
+
spec.email = 'namusyaka@gmail.com'
|
11
|
+
spec.files = %w( README.rdoc Ruby4Misawa-0.1.gemspec Gemfile Ruby4Misawa.rb )
|
12
|
+
spec.add_development_dependency('nokogiri')
|
13
|
+
end
|
data/Ruby4Misawa.rb
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
%w( uri open-uri optparse rubygems nokogiri ).each do | name |
|
4
|
+
require name
|
5
|
+
end
|
6
|
+
|
7
|
+
class Misawa
|
8
|
+
|
9
|
+
DOMAIN = 'http://jigokuno.com/'
|
10
|
+
CATEGORIES = {
|
11
|
+
"cecil" => 79,
|
12
|
+
"D-Matt" => 25,
|
13
|
+
"KAZ" => 1,
|
14
|
+
"KOUNOIKE" => 29,
|
15
|
+
"masa" => 13,
|
16
|
+
"masao" => 53,
|
17
|
+
"NAKAYAN" => 8,
|
18
|
+
"SYUN" => 24,
|
19
|
+
"ルシフェル" => 14,
|
20
|
+
"あつしさん" => 64,
|
21
|
+
"あの御方" => 37,
|
22
|
+
"しょうへい" => 66,
|
23
|
+
"すなお" => 38,
|
24
|
+
"たばっち" => 52,
|
25
|
+
"ちんちんでか男" => 57,
|
26
|
+
"つっちー" => 7,
|
27
|
+
"てづっちゃん" => 67,
|
28
|
+
"とりっぴー" => 82,
|
29
|
+
"なかじ" => 28,
|
30
|
+
"のぶちゃん" => 22,
|
31
|
+
"のぼる" => 49,
|
32
|
+
"のりすけ" => 21,
|
33
|
+
"はしもっさん" => 44,
|
34
|
+
"はまちゃん" => 55,
|
35
|
+
"ぴーなっつ" => 58,
|
36
|
+
"まみのパパ" => 56,
|
37
|
+
"りきお" => 85,
|
38
|
+
"エ~イチ" => 83,
|
39
|
+
"キヨシロー" => 17,
|
40
|
+
"キング" => 84,
|
41
|
+
"コウヘイ" => 3,
|
42
|
+
"シュナイダー" => 34,
|
43
|
+
"ショップ店員" => 12,
|
44
|
+
"ジーンズ" => 36,
|
45
|
+
"ジェイ" => 10,
|
46
|
+
"ソドム" => 78,
|
47
|
+
"タケ" => 54,
|
48
|
+
"チーポー" => 35,
|
49
|
+
"デスピサロ" => 46,
|
50
|
+
"ドリモグ" => 40,
|
51
|
+
"ナイト" => 50,
|
52
|
+
"ハリソン・フォード" => 41,
|
53
|
+
"バイトリーダー" => 71,
|
54
|
+
"ファイナルボム" => 74,
|
55
|
+
"フェイク" => 32,
|
56
|
+
"マイク" => 65,
|
57
|
+
"ミラージュ" => 5,
|
58
|
+
"ラッシュさん" => 19,
|
59
|
+
"リアル" => 81,
|
60
|
+
"リチャード" => 80,
|
61
|
+
"リュウー" => 26,
|
62
|
+
"レオン" => 59,
|
63
|
+
"吉岡" => 6,
|
64
|
+
"久志" => 51,
|
65
|
+
"玉木宏" => 43,
|
66
|
+
"健二" => 70,
|
67
|
+
"佐伯さん" => 76,
|
68
|
+
"砂漠の狼" => 63,
|
69
|
+
"坂本竜馬の子孫" => 27,
|
70
|
+
"桜井" => 39,
|
71
|
+
"時任" => 42,
|
72
|
+
"実行委員" => 47,
|
73
|
+
"小松っち" => 75,
|
74
|
+
"松尾" => 23,
|
75
|
+
"水谷" => 11,
|
76
|
+
"袖まくり" => 60,
|
77
|
+
"太陽 " => 68,
|
78
|
+
"代官山" => 33,
|
79
|
+
"大嶽一史" => 77,
|
80
|
+
"拓真" => 31,
|
81
|
+
"達也の兄ちゃん" => 72,
|
82
|
+
"痴漢" => 15,
|
83
|
+
"中村健" => 4,
|
84
|
+
"田部" => 20,
|
85
|
+
"東大生" => 45,
|
86
|
+
"湯上谷" => 16,
|
87
|
+
"藤井" => 9,
|
88
|
+
"道明寺" => 61,
|
89
|
+
"風雲児達" => 86,
|
90
|
+
"北岡" => 62,
|
91
|
+
"野村" => 2,
|
92
|
+
"野茂" => 30,
|
93
|
+
"零" => 69,
|
94
|
+
"零" => 73,
|
95
|
+
"和田" => 48
|
96
|
+
}
|
97
|
+
|
98
|
+
attr_reader :category, :page
|
99
|
+
|
100
|
+
def initialize(category, page = 0)
|
101
|
+
@category = CATEGORIES[category]
|
102
|
+
@page = page =~ /^[0-9]+?\.\.[0-9]+?$/ ? eval(page) : page
|
103
|
+
end
|
104
|
+
|
105
|
+
def scrape
|
106
|
+
create_uri.inject([]) do | result, uri |
|
107
|
+
body = get_body(uri)
|
108
|
+
Nokogiri.HTML(body).css('img.pict').map { | img | result << img['src'] } if body
|
109
|
+
result
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class << self;
|
114
|
+
|
115
|
+
def save_misawa(category, page)
|
116
|
+
misawa = self.new(category, page)
|
117
|
+
misawa.scrape.each_with_index do | src, i |
|
118
|
+
File.open("#{misawa.category}-#{i}.gif", 'w') { | f | f.write(misawa.get_body(src)) }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def uri_misawa(category, page)
|
123
|
+
misawa = self.new(category, page)
|
124
|
+
misawa.scrape.each_with_index do | src, i |
|
125
|
+
puts "#{misawa.category}-#{i} : #{src} "
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def method_missing(name, *args)
|
130
|
+
raise ArgumentError;
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
def get_body(uri)
|
136
|
+
begin
|
137
|
+
open(URI.encode(uri)).read
|
138
|
+
rescue OpenURI::HTTPError
|
139
|
+
return nil
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def create_uri
|
144
|
+
if @page.is_a?(Range)
|
145
|
+
base = "#{DOMAIN}/?cid=#{@category}&page="
|
146
|
+
@page.map { | i | "#{base}#{i}" }
|
147
|
+
else
|
148
|
+
["#{DOMAIN}/?cid=#{@category}&page=#{@page}"]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
if $0 === __FILE__
|
155
|
+
|
156
|
+
OptionParser.new do | opt |
|
157
|
+
|
158
|
+
arguments = {}
|
159
|
+
|
160
|
+
opt.on('-t [TYPE]', '--type [TYPE]') do | value |
|
161
|
+
arguments[:type] = value
|
162
|
+
end
|
163
|
+
opt.on('-p [PAGE]', '--page [PAGE]') do | value |
|
164
|
+
arguments[:page] = value
|
165
|
+
end
|
166
|
+
opt.on('-c [CATEGORY]', '--category [CATEGORY]') do | value |
|
167
|
+
arguments[:category] = value
|
168
|
+
end
|
169
|
+
|
170
|
+
opt.parse!(ARGV)
|
171
|
+
Misawa.send("#{arguments[:type] || 'uri'}_misawa", arguments[:category], arguments[:page])
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Ruby4Misawa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- namusyaka
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: &2151914520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2151914520
|
25
|
+
description: 地獄のミサワブログにあるURLがとれたり、そのまま画像を保存したりできます。
|
26
|
+
email: namusyaka@gmail.com
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- README.rdoc
|
32
|
+
- Ruby4Misawa-0.1.gemspec
|
33
|
+
- Gemfile
|
34
|
+
- Ruby4Misawa.rb
|
35
|
+
homepage: https://github.com/namusyaka/Ruby4Misawa
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.10
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: スクレイピングライブラリ for 地獄のミサワ
|
59
|
+
test_files: []
|