spidey-mongo 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/spidey/strategies/mongo.rb +7 -5
- data/lib/spidey-mongo/version.rb +1 -1
- data/spec/spidey/strategies/mongo_spec.rb +3 -0
- metadata +16 -16
@@ -25,11 +25,12 @@ module Spidey::Strategies
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def record(data)
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
doc = data.merge('spider' => self.class.name)
|
29
|
+
$stderr.puts "Recording #{doc.inspect.truncate(500)}" if verbose
|
30
|
+
if respond_to?(:result_key) && key = result_key(doc)
|
31
|
+
result_collection.update({'key' => key}, {'$set' => doc}, upsert: true)
|
31
32
|
else
|
32
|
-
result_collection.insert
|
33
|
+
result_collection.insert doc
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
@@ -43,7 +44,8 @@ module Spidey::Strategies
|
|
43
44
|
|
44
45
|
def add_error(attrs)
|
45
46
|
error = attrs.delete(:error)
|
46
|
-
|
47
|
+
doc = attrs.merge(created_at: Time.now, error: error.class.name, message: error.message, spider: self.class.name)
|
48
|
+
error_collection.insert doc
|
47
49
|
$stderr.puts "Error on #{attrs[:url]}. #{error.class}: #{error.message}" if verbose
|
48
50
|
end
|
49
51
|
|
data/lib/spidey-mongo/version.rb
CHANGED
@@ -25,6 +25,7 @@ describe Spidey::Strategies::Mongo do
|
|
25
25
|
it "should add initial URLs to collection" do
|
26
26
|
doc = @db['urls'].find_one(url: "http://www.cnn.com")
|
27
27
|
doc['handler'].should == :process_home
|
28
|
+
doc['spider'].should == 'TestSpider'
|
28
29
|
end
|
29
30
|
|
30
31
|
it "should not add duplicate URLs" do
|
@@ -38,6 +39,7 @@ describe Spidey::Strategies::Mongo do
|
|
38
39
|
doc = @db['results'].find_one
|
39
40
|
doc['detail_url'].should == 'http://www.cnn.com'
|
40
41
|
doc['foo'].should == 'bar'
|
42
|
+
doc['spider'].should == 'TestSpider'
|
41
43
|
end
|
42
44
|
|
43
45
|
it "should update existing result" do
|
@@ -53,6 +55,7 @@ describe Spidey::Strategies::Mongo do
|
|
53
55
|
doc['url'].should == 'http://www.cnn.com'
|
54
56
|
doc['handler'].should == :blah
|
55
57
|
doc['message'].should == 'WTF'
|
58
|
+
doc['spider'].should == 'TestSpider'
|
56
59
|
end
|
57
60
|
|
58
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spidey-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70172417847540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70172417847540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70172417846740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70172417846740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ruby-debug19
|
38
|
-
requirement: &
|
38
|
+
requirement: &70172417845560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70172417845560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: spidey
|
49
|
-
requirement: &
|
49
|
+
requirement: &70172417844480 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70172417844480
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mongo
|
60
|
-
requirement: &
|
60
|
+
requirement: &70172417830340 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70172417830340
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bson_ext
|
71
|
-
requirement: &
|
71
|
+
requirement: &70172417829000 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70172417829000
|
80
80
|
description: Implements a MongoDB back-end for Spidey, a framework for crawling and
|
81
81
|
scraping web sites.
|
82
82
|
email:
|
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
hash: -
|
114
|
+
hash: -2776115176941497831
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
segments:
|
122
122
|
- 0
|
123
|
-
hash: -
|
123
|
+
hash: -2776115176941497831
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project: spidey-mongo
|
126
126
|
rubygems_version: 1.8.10
|