ruby2ch 0.0.4 → 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.
- data/README +17 -0
- data/lib/ruby2ch/board.rb +34 -0
- data/lib/ruby2ch/datparse.rb +46 -0
- data/lib/ruby2ch/thre.rb +3 -1
- data/lib/ruby2ch/version.rb +1 -1
- data/lib/ruby2ch.rb +2 -0
- metadata +4 -2
data/README
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'ruby2ch/thre'
|
3
|
+
require 'thread'
|
4
|
+
require 'ruby2ch/datparse'
|
5
|
+
include Ruby2ch
|
6
|
+
|
7
|
+
module Ruby2ch
|
8
|
+
class Board
|
9
|
+
def initialize(url)
|
10
|
+
@agent = Mechanize.new
|
11
|
+
@page = @agent.get(url)
|
12
|
+
@links = @page.links.map{|link| link.href}.map{|link| link.split("/")[0]}
|
13
|
+
@links.map!{|link| url.sub("/news/subback.html","/test/read.cgi/news/") + link}
|
14
|
+
@links.select!{|x| /\/\d*$/ =~x}
|
15
|
+
end
|
16
|
+
|
17
|
+
def threads
|
18
|
+
threads = []
|
19
|
+
@links.each{|link|
|
20
|
+
threads << Thread.start(link){|link| Dat.new(link)}
|
21
|
+
}
|
22
|
+
|
23
|
+
threads.map!{|thre|
|
24
|
+
thre.join.value
|
25
|
+
}
|
26
|
+
|
27
|
+
return threads
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_accessor :links
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'mechanize'
|
3
|
+
require 'kconv'
|
4
|
+
module Ruby2ch
|
5
|
+
class Dat
|
6
|
+
def initialize(url)
|
7
|
+
#http://uni.2ch.net/test/read.cgi/news/1322032301/l50
|
8
|
+
#http://bg20.2ch.net/test/r.so/uni.2ch.net/news/1322032301/
|
9
|
+
url_elements = url.split("/")
|
10
|
+
@dat_url = "http://bg20.2ch.net/test/r.so/" + url_elements[2] + "/" + url_elements[5] + "/" + url_elements[6] + "/"
|
11
|
+
@agent = Mechanize.new
|
12
|
+
@page = @agent.get(@dat_url).body.toutf8
|
13
|
+
|
14
|
+
@page = @page.split("\n").map{|res| dat_parse(res).flatten}.delete_if{|res| res == []}
|
15
|
+
@page.map{|res|
|
16
|
+
res[6] = res[6].gsub("<>","").gsub("<br>","\n")
|
17
|
+
unless res[5] == nil
|
18
|
+
res[5] = res[5].scan(/.*>>(\d+).*/).flatten[0]
|
19
|
+
res[5] = ">>" + res[5] + res[6]
|
20
|
+
else
|
21
|
+
res[5] = res[6]
|
22
|
+
end
|
23
|
+
res.pop
|
24
|
+
|
25
|
+
}
|
26
|
+
@thre = @page.map{|res|
|
27
|
+
{name: res[0],place: res[1], date: res[2], id: res[3], point: res[4],text: res[5]}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_a
|
32
|
+
@array = @page.split("\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
def dat_parse(res)
|
36
|
+
res_array = res.scan(/(^\S+)\<\/b\>(\(.*\))\<b\>\<\>\S*\<\>(.+)\sID:(\S+)\s*(BE.*)*\<\>\s(\<a.*\<\/a\>)*(.*)/)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
attr_accessor :dat_url,:page
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
data/lib/ruby2ch/thre.rb
CHANGED
@@ -13,7 +13,9 @@ module Ruby2ch
|
|
13
13
|
@no = @name.map{|n| n[0]}
|
14
14
|
@hn = @name.map{|n| n[1]}
|
15
15
|
name_split = @name.map{|n| n[2].split(" ")}
|
16
|
-
@ids = name_split.map{|n| n[2]}.uniq.map{|id|
|
16
|
+
@ids = name_split.map{|n| n[2]}.uniq.map{|id|
|
17
|
+
puts id
|
18
|
+
id.sub("ID:","")}
|
17
19
|
@date1 = name_split.map{|n| n[0]}.map{|n| n.sub(/\(.\)/,"")}
|
18
20
|
@time = name_split.map{|n| n[1]}
|
19
21
|
@date = @date1[0] + " " + @time[0]
|
data/lib/ruby2ch/version.rb
CHANGED
data/lib/ruby2ch.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2ch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-24 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: 2ch for ruby
|
15
15
|
email:
|
@@ -23,6 +23,8 @@ files:
|
|
23
23
|
- README
|
24
24
|
- Rakefile
|
25
25
|
- lib/ruby2ch.rb
|
26
|
+
- lib/ruby2ch/board.rb
|
27
|
+
- lib/ruby2ch/datparse.rb
|
26
28
|
- lib/ruby2ch/news.rb
|
27
29
|
- lib/ruby2ch/thre.rb
|
28
30
|
- lib/ruby2ch/version.rb
|