crown 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/README.rdoc +14 -11
- data/VERSION +1 -1
- data/crown.gemspec +15 -5
- data/example/entrylist.rb +69 -0
- data/example/fbcount.rb +1 -1
- data/example/hbentry.rb +1 -1
- data/example/rtcount.rb +1 -0
- data/example/twcount.rb +1 -1
- data/example/{annual.rb → urilist.rb} +21 -26
- data/lib/crown.rb +1 -1
- data/{example/hbtrace.rb → lib/crown/amazon.rb} +8 -23
- data/lib/crown/amazon/crawler.rb +159 -0
- data/lib/crown/amazon/ecs.rb +385 -0
- data/lib/crown/amazon/entrylist.rb +171 -0
- data/lib/crown/backtype.rb +2 -2
- data/lib/crown/buzzurl.rb +2 -2
- data/lib/crown/cgm.rb +8 -0
- data/lib/crown/cgm/countable.rb +1 -1
- data/lib/crown/cgm/summarizable.rb +1 -1
- data/lib/crown/delicious.rb +2 -2
- data/lib/crown/facebook.rb +4 -4
- data/lib/crown/facebook/entry.rb +5 -3
- data/lib/crown/google.rb +38 -0
- data/lib/crown/google/plusone.rb +65 -0
- data/lib/crown/google/plusone/counter.rb +102 -0
- data/lib/crown/hatena/bookmark.rb +7 -7
- data/lib/crown/hatena/bookmark/entry.rb +70 -68
- data/lib/crown/hatena/bookmark/entrylist.rb +98 -0
- data/lib/crown/hatena/bookmark/urilist.rb +349 -0
- data/lib/crown/http-wrapper.rb +0 -1
- data/lib/crown/linkedin.rb +60 -0
- data/lib/crown/linkedin/counter.rb +81 -0
- data/lib/crown/livedoor/clip.rb +2 -2
- data/lib/crown/livedoor/clip/counter.rb +1 -1
- data/lib/crown/livedoor/reader.rb +2 -2
- data/lib/crown/topsy.rb +2 -3
- data/lib/crown/tweetmeme.rb +2 -2
- data/lib/crown/twitter.rb +1 -1
- data/lib/crown/twitter/uri.rb +2 -2
- data/lib/crown/twitter/user.rb +4 -4
- data/lib/crown/twitter/user/entry.rb +26 -6
- data/lib/crown/yahoo/bookmark.rb +3 -7
- data/test/crown-test.rb +34 -12
- metadata +17 -7
- data/lib/crown/hatena/bookmark/linktrace.rb +0 -135
data/ChangeLog
CHANGED
data/README.rdoc
CHANGED
@@ -19,26 +19,29 @@ crown は Ruby で書かれた雑多なライブラリです.各種 Web サー
|
|
19
19
|
|
20
20
|
== History
|
21
21
|
|
22
|
+
=== 0.1.1 / 2012-03-01
|
23
|
+
* Google+1, LinkedIn モジュールを追加。
|
24
|
+
|
22
25
|
=== 0.1.0 / 2012-01-24
|
23
26
|
* Amazon 関連のモジュールを削除
|
24
|
-
* これまで proxy_host, proxy_port や api_key
|
25
|
-
各種メソッドのオプション引数を options
|
26
|
-
|
27
|
-
* Crown::Facebook.count
|
28
|
-
旧バージョンの count メソッドに当たるものは Crown::Facebook.summary
|
27
|
+
* これまで proxy_host, proxy_port や api_key 等、使用する API によって微妙に引数が異なっていた
|
28
|
+
各種メソッドのオプション引数を options と言う引数で統一。今後は,必要なオプション情報を
|
29
|
+
ハッシュ形式で作成し、そのオブジェクトを第 2 引数に指定する。
|
30
|
+
* Crown::Facebook.count メソッドの返り値を「いいね!」、「シェア」の合計値のみに変更。
|
31
|
+
旧バージョンの count メソッドに当たるものは Crown::Facebook.summary メソッドとして用意している。
|
29
32
|
* Delicious の API の仕様変更に対応
|
30
33
|
|
31
34
|
=== 0.0.5 / 2011-02-24
|
32
|
-
* Rakefile
|
35
|
+
* Rakefile にライブラリの依存関係に関する記述を追加。
|
33
36
|
|
34
37
|
=== 0.0.4 / 2011-02-19
|
35
|
-
* Livedoor Reader
|
36
|
-
* Facebook
|
37
|
-
* Topsy, TweetMeme, BackType (BackTweets)
|
38
|
+
* Livedoor Reader モジュールを追加。
|
39
|
+
* Facebook モジュールを追加。
|
40
|
+
* Topsy, TweetMeme, BackType (BackTweets) モジュールを追加。
|
38
41
|
|
39
42
|
=== 0.0.1 / 2011-02-18
|
40
|
-
*
|
43
|
+
* 最初の公開バージョン。
|
41
44
|
|
42
45
|
== Copyright
|
43
46
|
|
44
|
-
Copyright (c) 2008 -
|
47
|
+
Copyright (c) 2008 - 2012 clown. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/crown.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{crown}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{clown}]
|
12
|
-
s.date = %q{2012-01
|
12
|
+
s.date = %q{2012-03-01}
|
13
13
|
s.description = %q{crown is uncategorized ruby libraries, which is added according to author's mood :-D}
|
14
14
|
s.email = %q{tt.clown@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,17 +25,21 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"crown.gemspec",
|
28
|
-
"example/annual.rb",
|
29
28
|
"example/cgmcount.rb",
|
29
|
+
"example/entrylist.rb",
|
30
30
|
"example/fbcount.rb",
|
31
31
|
"example/feedcount.rb",
|
32
32
|
"example/hbcount.rb",
|
33
33
|
"example/hbentry.rb",
|
34
|
-
"example/hbtrace.rb",
|
35
34
|
"example/rtcount.rb",
|
36
35
|
"example/sbmcount.rb",
|
37
36
|
"example/twcount.rb",
|
37
|
+
"example/urilist.rb",
|
38
38
|
"lib/crown.rb",
|
39
|
+
"lib/crown/amazon.rb",
|
40
|
+
"lib/crown/amazon/crawler.rb",
|
41
|
+
"lib/crown/amazon/ecs.rb",
|
42
|
+
"lib/crown/amazon/entrylist.rb",
|
39
43
|
"lib/crown/backtype.rb",
|
40
44
|
"lib/crown/backtype/counter.rb",
|
41
45
|
"lib/crown/buzzurl.rb",
|
@@ -48,12 +52,18 @@ Gem::Specification.new do |s|
|
|
48
52
|
"lib/crown/facebook.rb",
|
49
53
|
"lib/crown/facebook/counter.rb",
|
50
54
|
"lib/crown/facebook/entry.rb",
|
55
|
+
"lib/crown/google.rb",
|
56
|
+
"lib/crown/google/plusone.rb",
|
57
|
+
"lib/crown/google/plusone/counter.rb",
|
51
58
|
"lib/crown/hatena.rb",
|
52
59
|
"lib/crown/hatena/bookmark.rb",
|
53
60
|
"lib/crown/hatena/bookmark/counter.rb",
|
54
61
|
"lib/crown/hatena/bookmark/entry.rb",
|
55
|
-
"lib/crown/hatena/bookmark/
|
62
|
+
"lib/crown/hatena/bookmark/entrylist.rb",
|
63
|
+
"lib/crown/hatena/bookmark/urilist.rb",
|
56
64
|
"lib/crown/http-wrapper.rb",
|
65
|
+
"lib/crown/linkedin.rb",
|
66
|
+
"lib/crown/linkedin/counter.rb",
|
57
67
|
"lib/crown/livedoor.rb",
|
58
68
|
"lib/crown/livedoor/clip.rb",
|
59
69
|
"lib/crown/livedoor/clip/counter.rb",
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/ruby -Ku
|
2
|
+
# --------------------------------------------------------------------------- #
|
3
|
+
#
|
4
|
+
# entrylist.rb
|
5
|
+
#
|
6
|
+
# Copyright (c) 2008 - 2011, clown.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions
|
10
|
+
# are met:
|
11
|
+
#
|
12
|
+
# - Redistributions of source code must retain the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer.
|
14
|
+
# - Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in the
|
16
|
+
# documentation and/or other materials provided with the distribution.
|
17
|
+
# - No names of its contributors may be used to endorse or promote
|
18
|
+
# products derived from this software without specific prior written
|
19
|
+
# permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
# --------------------------------------------------------------------------- #
|
34
|
+
require 'rubygems'
|
35
|
+
require 'crown/hatena/bookmark'
|
36
|
+
|
37
|
+
# --------------------------------------------------------------------------- #
|
38
|
+
#
|
39
|
+
# filters
|
40
|
+
#
|
41
|
+
# �������i���ău�b�N�}�[�N���ꗗ���擾�������ꍇ�́C
|
42
|
+
# �n�b�V���`���ŕK�v�Ȃ��̂��w�肷��D
|
43
|
+
# �w��\�ȏ����́C:type, :category, :sort, :threshold �������݂���D
|
44
|
+
#
|
45
|
+
# --------------------------------------------------------------------------- #
|
46
|
+
filters = {
|
47
|
+
:sort => :hot,
|
48
|
+
# :threshold => 10,
|
49
|
+
# :uri => 'http://d.hatena.ne.jp/tt_clown/'
|
50
|
+
}
|
51
|
+
|
52
|
+
# --------------------------------------------------------------------------- #
|
53
|
+
# main
|
54
|
+
# --------------------------------------------------------------------------- #
|
55
|
+
n = 1
|
56
|
+
Crown::Hatena::Bookmark::EntryList.start(filters) { |session|
|
57
|
+
# �u�b�N�}�[�N���擾 API ���R�[������Ԋu��b�P�ʂŐݒ肷��D
|
58
|
+
# �T�[�o�̕��ד����l�����Č��肷�鎖�D
|
59
|
+
# �f�t�H���g�l�� 30�b
|
60
|
+
# session.interval = 10
|
61
|
+
|
62
|
+
session.get { |entry|
|
63
|
+
printf("%d %s\n", n, entry.uri)
|
64
|
+
printf(" %s\n", entry.title)
|
65
|
+
printf(" %d users\n", entry.count)
|
66
|
+
n += 1
|
67
|
+
break if (n > 5)
|
68
|
+
}
|
69
|
+
}
|
data/example/fbcount.rb
CHANGED
@@ -45,7 +45,7 @@ require 'crown'
|
|
45
45
|
#
|
46
46
|
# --------------------------------------------------------------------------- #
|
47
47
|
ARGV.each { |uri|
|
48
|
-
info = Crown::Facebook.
|
48
|
+
info = Crown::Facebook.summary(uri)
|
49
49
|
printf("%s\n", uri)
|
50
50
|
printf(" + like : %8d\n", info.like)
|
51
51
|
printf(" + total : %8d\n", info.total)
|
data/example/hbentry.rb
CHANGED
@@ -46,7 +46,7 @@ require 'crown/hatena/bookmark'
|
|
46
46
|
File.open(ARGV[0]) { |file|
|
47
47
|
file.each { |line|
|
48
48
|
line.chomp!
|
49
|
-
result = Crown::Hatena::Bookmark.
|
49
|
+
result = Crown::Hatena::Bookmark.summary(line)
|
50
50
|
printf("%s (%d users)\n", result.uri, result.count)
|
51
51
|
|
52
52
|
# ブクマした日付で昇順にソートした後,出力する.
|
data/example/rtcount.rb
CHANGED
@@ -51,6 +51,7 @@ BACKTYPE_APIKEY = "your_api_key"
|
|
51
51
|
# --------------------------------------------------------------------------- #
|
52
52
|
ARGV.each { |uri|
|
53
53
|
printf("%s\n", uri)
|
54
|
+
printf(" + twitter : %8d\n", Crown::Twitter::URI.count(uri))
|
54
55
|
printf(" + topsy : %8d\n", Crown::Topsy.count(uri))
|
55
56
|
printf(" + tweetmeme : %8d\n", Crown::TweetMeme.count(uri))
|
56
57
|
printf(" + backtype : %8d\n", Crown::BackType.count(uri, BACKTYPE_APIKEY))
|
data/example/twcount.rb
CHANGED
@@ -45,7 +45,7 @@ require 'crown'
|
|
45
45
|
#
|
46
46
|
# --------------------------------------------------------------------------- #
|
47
47
|
ARGV.each { |screen_name|
|
48
|
-
info = Crown::Twitter.count(screen_name)
|
48
|
+
info = Crown::Twitter::User.count(screen_name)
|
49
49
|
printf("%s\n", screen_name)
|
50
50
|
printf(" + status : %8d\n", info.status)
|
51
51
|
printf(" + friend : %8d\n", info.friend)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/ruby -Ku
|
2
2
|
# --------------------------------------------------------------------------- #
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# entrylist.rb
|
5
5
|
#
|
6
6
|
# Copyright (c) 2008 - 2011, clown.
|
7
7
|
#
|
@@ -34,36 +34,31 @@
|
|
34
34
|
require 'rubygems'
|
35
35
|
require 'crown/hatena/bookmark'
|
36
36
|
|
37
|
-
PREFIX = "entrylist?sort=count&url="
|
38
|
-
|
39
37
|
# --------------------------------------------------------------------------- #
|
40
38
|
#
|
41
|
-
#
|
39
|
+
# filters
|
42
40
|
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
# ARGV[2]: 取得件数(オプション)
|
41
|
+
# 条件を絞ってブックマーク情報一覧を取得したい場合は,
|
42
|
+
# ハッシュ形式で必要なものを指定する.
|
43
|
+
# 指定可能な条件は,:type, :category, :sort, :threshold 等が存在する.
|
47
44
|
#
|
48
45
|
# --------------------------------------------------------------------------- #
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
filters = {
|
47
|
+
:sort => :hot,
|
48
|
+
# :threshold => 10,
|
49
|
+
# :uri => 'http://d.hatena.ne.jp/tt_clown/'
|
50
|
+
}
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
# --------------------------------------------------------------------------- #
|
53
|
+
# main
|
54
|
+
# --------------------------------------------------------------------------- #
|
55
|
+
n = 1
|
56
|
+
Crown::Hatena::Bookmark::URIList.start(filters) { |session|
|
57
|
+
session.get { |entry|
|
58
|
+
printf("%d %s\n", n, entry.uri)
|
59
|
+
printf(" %s\n", entry.title)
|
60
|
+
printf(" %s\n", entry.date.to_s)
|
61
|
+
n += 1
|
62
|
+
break if (n > 10)
|
60
63
|
}
|
61
|
-
|
62
|
-
if (v != nil && !v.empty? && v[0][1].date.year == year)
|
63
|
-
printf("+ %s (%d users)\n", entry.uri, entry.count)
|
64
|
-
i += 1
|
65
|
-
break if (i >= limit)
|
66
|
-
end
|
67
|
-
|
68
|
-
sleep 5
|
69
64
|
}
|
data/lib/crown.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
# --------------------------------------------------------------------------- #
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# amazon.rb
|
5
5
|
#
|
6
|
-
# Copyright (c) 2008 -
|
6
|
+
# Copyright (c) 2008 - 2012, clown.
|
7
7
|
#
|
8
8
|
# Redistribution and use in source and binary forms, with or without
|
9
9
|
# modification, are permitted provided that the following conditions
|
@@ -31,23 +31,8 @@
|
|
31
31
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
32
|
#
|
33
33
|
# --------------------------------------------------------------------------- #
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# 引数に指定されたパスに表示されている各はてなブックマーク URL の情報を
|
40
|
-
# 取得して出力する.
|
41
|
-
#
|
42
|
-
# Parameters:
|
43
|
-
# ARGV[0]: はてなブックマーク URL の一覧が記載されているパス
|
44
|
-
# ARGV[1]: 最大出力件数
|
45
|
-
#
|
46
|
-
# --------------------------------------------------------------------------- #
|
47
|
-
limit = (ARGV.length > 1) ? ARGV[1].to_i : 10
|
48
|
-
i = 1
|
49
|
-
Crown::Hatena::Bookmark.each(ARGV[0]) { |entry|
|
50
|
-
printf("%3d %s (%d users)\n", i, entry.uri, entry.count)
|
51
|
-
break if (i >= limit)
|
52
|
-
i += 1
|
53
|
-
}
|
34
|
+
module Crown
|
35
|
+
module Amazon
|
36
|
+
require 'crown/amazon/crawler'
|
37
|
+
end # Amazon
|
38
|
+
end # Crown
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# --------------------------------------------------------------------------- #
|
3
|
+
#
|
4
|
+
# amazon/crawler.rb
|
5
|
+
#
|
6
|
+
# Copyright (c) 2008 - 2012, clown.
|
7
|
+
#
|
8
|
+
# Redistribution and use in source and binary forms, with or without
|
9
|
+
# modification, are permitted provided that the following conditions
|
10
|
+
# are met:
|
11
|
+
#
|
12
|
+
# - Redistributions of source code must retain the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer.
|
14
|
+
# - Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in the
|
16
|
+
# documentation and/or other materials provided with the distribution.
|
17
|
+
# - No names of its contributors may be used to endorse or promote
|
18
|
+
# products derived from this software without specific prior written
|
19
|
+
# permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
25
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
26
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
27
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
#
|
33
|
+
# --------------------------------------------------------------------------- #
|
34
|
+
module Crown
|
35
|
+
module Amazon
|
36
|
+
require 'crown/amazon/entrylist'
|
37
|
+
|
38
|
+
# ------------------------------------------------------------------- #
|
39
|
+
#
|
40
|
+
# Crawler
|
41
|
+
#
|
42
|
+
# 指定した URL に記述されてある Amazon の ASIN コードを抽出し,
|
43
|
+
# それらの商品情報を取得するためのクラス.
|
44
|
+
#
|
45
|
+
# ------------------------------------------------------------------- #
|
46
|
+
class Crawler
|
47
|
+
# --------------------------------------------------------------- #
|
48
|
+
# structures
|
49
|
+
# --------------------------------------------------------------- #
|
50
|
+
Response = Struct.new(:asin, :title, :author, :publisher, :price, :date, :count)
|
51
|
+
|
52
|
+
# --------------------------------------------------------------- #
|
53
|
+
# accessors
|
54
|
+
# --------------------------------------------------------------- #
|
55
|
+
attr_accessor :threshold, :interval, :entries, :uri_count
|
56
|
+
|
57
|
+
# --------------------------------------------------------------- #
|
58
|
+
# initialize
|
59
|
+
# --------------------------------------------------------------- #
|
60
|
+
def initialize()
|
61
|
+
@threshold = 5
|
62
|
+
@interval = 5
|
63
|
+
@entries = Array.new
|
64
|
+
@uri_count = 0
|
65
|
+
end
|
66
|
+
|
67
|
+
# --------------------------------------------------------------- #
|
68
|
+
# clear
|
69
|
+
# --------------------------------------------------------------- #
|
70
|
+
def clear()
|
71
|
+
@entries.clear
|
72
|
+
@uri_count = 0
|
73
|
+
end
|
74
|
+
|
75
|
+
# --------------------------------------------------------------- #
|
76
|
+
#
|
77
|
+
# get
|
78
|
+
#
|
79
|
+
# 指定した URL に記述されてある Amazon の ASIN コードを抽出し,
|
80
|
+
# それらの商品情報を取得する.uris には,クロールする URL の
|
81
|
+
# 配列,または URL 一覧が記載されてあるファイルへのパスを指定
|
82
|
+
# する.
|
83
|
+
#
|
84
|
+
# --------------------------------------------------------------- #
|
85
|
+
def get(uris, options = {})
|
86
|
+
case uris
|
87
|
+
when String then v = load(uris);
|
88
|
+
when Array then v = uris;
|
89
|
+
else return [];
|
90
|
+
end
|
91
|
+
|
92
|
+
asins = Hash.new
|
93
|
+
v.each { |uri|
|
94
|
+
begin
|
95
|
+
exits = false
|
96
|
+
::Crown::Amazon::EntryList.new.asin(uri, options) { |asin|
|
97
|
+
if (asins.include?(asin)) then asins[asin] += 1;
|
98
|
+
else asins[asin] = 1;
|
99
|
+
end
|
100
|
+
exists = true
|
101
|
+
}
|
102
|
+
@uri_count += 1 if (exists)
|
103
|
+
rescue Exception => e
|
104
|
+
next
|
105
|
+
end
|
106
|
+
}
|
107
|
+
|
108
|
+
asins.to_a.sort { |x, y| y[1] <=> x[1] }.each { |asin|
|
109
|
+
break if (asin[1] < @threshold)
|
110
|
+
response = ::Amazon::Ecs.item_lookup(asin[0], { :response_group => 'Medium' })
|
111
|
+
next if (response == nil || response.items.length == 0)
|
112
|
+
|
113
|
+
x = response.first_item
|
114
|
+
entry = Response.new
|
115
|
+
entry.asin = alternate(x.get('ASIN'), '')
|
116
|
+
entry.title = alternate(x.get('ItemAttributes/Title'), '')
|
117
|
+
entry.author = alternate(x.get_array('ItemAttributes/Author').join(','), '')
|
118
|
+
entry.publisher = alternate(x.get('ItemAttributes/Publisher'), '')
|
119
|
+
entry.price = alternate(x.get('ItemAttributes/ListPrice/Amount'), '')
|
120
|
+
entry.date = alternate(x.get('ItemAttributes/ReleaseDate'), '')
|
121
|
+
entry.date = alternate(x.get('ItemAttributes/PublicationDate'), '') if (entry.date == nil || entry.date.length == 0)
|
122
|
+
entry.count = asin[1]
|
123
|
+
|
124
|
+
yield entry if (block_given?)
|
125
|
+
@entries.push(entry)
|
126
|
+
sleep(@interval)
|
127
|
+
}
|
128
|
+
|
129
|
+
return @entries
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
# --------------------------------------------------------------- #
|
134
|
+
# load
|
135
|
+
# --------------------------------------------------------------- #
|
136
|
+
def load(path)
|
137
|
+
begin
|
138
|
+
v = Array.new
|
139
|
+
File.open(path) { |f|
|
140
|
+
f.each { |line|
|
141
|
+
v.push(line.chomp)
|
142
|
+
}
|
143
|
+
}
|
144
|
+
return v
|
145
|
+
rescue Exception => e
|
146
|
+
return []
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# --------------------------------------------------------------- #
|
151
|
+
# alternate
|
152
|
+
# --------------------------------------------------------------- #
|
153
|
+
def alternate(value, alt)
|
154
|
+
return (value != nil) ? value : alt
|
155
|
+
end
|
156
|
+
|
157
|
+
end # Crawler
|
158
|
+
end # Amazon
|
159
|
+
end # Crown
|