ruboty-bokete 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruboty/bokete/client.rb +36 -33
- data/lib/ruboty/bokete/version.rb +1 -1
- data/lib/ruboty/handlers/bokete.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f98edcf8358f16cdd3aaf186045b564ffdd87c6
|
4
|
+
data.tar.gz: 358ee77031f53d2c18bd97e950b0521e81561384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c589ffc54172226212e9c16fd62ce4f4277a727cabbcdb673099c4713adf6831c6c9203ea2421af03da33496b9c69e34380ea8b2b477a260119141d29cfea279
|
7
|
+
data.tar.gz: 3229a9e4169193e35ecf65c067bcc9c2cde0bd6d59c5bc9787da0bd336efbc3875d74a15789ecd7c9ba680a74c7faf05ea8a7128cc0ad3aa0e716fb5347bbb6d
|
data/lib/ruboty/bokete/client.rb
CHANGED
@@ -1,47 +1,50 @@
|
|
1
1
|
require 'mechanize'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Ruboty
|
4
|
+
module Bokete
|
5
|
+
class Client
|
6
|
+
BOKETE_URL = 'http://bokete.jp'
|
7
|
+
|
8
|
+
def initialize(max_results: 30)
|
9
|
+
@max_results = max_results
|
10
|
+
@agent = Mechanize.new
|
11
|
+
end
|
5
12
|
|
6
|
-
|
7
|
-
|
8
|
-
@agent = Mechanize.new
|
9
|
-
end
|
13
|
+
def get(mode)
|
14
|
+
results = []
|
10
15
|
|
11
|
-
|
12
|
-
|
16
|
+
@agent.get("#{BOKETE_URL}/boke/#{mode}") do |page|
|
17
|
+
target_page = page
|
13
18
|
|
14
|
-
|
15
|
-
|
19
|
+
while results.size < @max_results
|
20
|
+
images = scraping_from_page(target_page)
|
21
|
+
results.concat(images)
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
target_page = get_next_page(target_page)
|
24
|
+
break if target_page.nil?
|
25
|
+
end
|
26
|
+
end
|
20
27
|
|
21
|
-
|
22
|
-
break if target_page.nil?
|
28
|
+
results
|
23
29
|
end
|
24
|
-
end
|
25
|
-
|
26
|
-
results
|
27
|
-
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
def scraping_from_page(page)
|
32
|
+
page.search('.boke').map do |node|
|
33
|
+
node.children.each_with_object({}) do |child, hash|
|
34
|
+
case child.name
|
35
|
+
when 'div'
|
36
|
+
img = child.children.children.children.detect {|o| o.name == 'img' }
|
37
|
+
hash[:url] ||= img.attribute('src').value rescue nil
|
38
|
+
when 'h3'
|
39
|
+
hash[:boke] = child.text
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
35
44
|
|
36
|
-
|
37
|
-
|
45
|
+
def get_next_page(page)
|
46
|
+
page.links_with(href: /\?page/)[-1].click rescue nil
|
38
47
|
end
|
39
48
|
end
|
40
|
-
|
41
|
-
images
|
42
|
-
end
|
43
|
-
|
44
|
-
def get_next_page(page)
|
45
|
-
page.links_with(href: /\?page/)[-1].click rescue nil
|
46
49
|
end
|
47
50
|
end
|
@@ -11,9 +11,9 @@ module Ruboty
|
|
11
11
|
on /bokete (?<mode>.+)/, name: 'bokete', description: 'Get a bokete'
|
12
12
|
|
13
13
|
def initialize(*args)
|
14
|
-
super
|
14
|
+
super(*args)
|
15
15
|
|
16
|
-
@client = Client.new
|
16
|
+
@client = Ruboty::Bokete::Client.new
|
17
17
|
end
|
18
18
|
|
19
19
|
def bokete(message)
|
@@ -33,7 +33,7 @@ module Ruboty
|
|
33
33
|
end
|
34
34
|
|
35
35
|
result = JSON.parse(brain[mode]).sample
|
36
|
-
message.reply(result)
|
36
|
+
message.reply((result['url'].start_with?('//') ? 'http:' + result['url'] : result['url']) + "\n" + result['boke'])
|
37
37
|
end
|
38
38
|
|
39
39
|
def brain
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-bokete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.5.1
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Ruboty handler to get a bokete.
|