samao 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -41
- data/lib/samao/detector.rb +4 -3
- data/lib/samao/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8052607754894bc0b6aab5725ced6198df5fc63a
|
4
|
+
data.tar.gz: 17102ace2e60b4eea948d1ee2263fe090381cc15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24e2ef9f4883c62cb2ed5bd6925e9bf4990f522fd62a1a2f03534fee96ab7fc0a728dac663b92210a7a539229c3bbcdedf38297d89348b5d593f92a4ef459f9b
|
7
|
+
data.tar.gz: d72849be792f00b93b58fae10374b42359f8d51d67f9d82f0325162680f8f269bdf435596b5f6b8b1d09f3ca5e88f2b097312292ac21999ffcd418cc4ec1c415
|
data/README.md
CHANGED
@@ -22,47 +22,52 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
25
|
+
```ruby
|
26
|
+
#!/usr/bin/env ruby
|
27
|
+
require 'samao'
|
28
|
+
|
29
|
+
# create samao detector
|
30
|
+
samao = Samao::Detector.new
|
31
|
+
|
32
|
+
# set max concurrent level
|
33
|
+
samao.concurrent 3
|
34
|
+
|
35
|
+
# set base url and start page
|
36
|
+
samao.baseurl 'https://github.com'
|
37
|
+
samao.from '/Lax?tab=repositories'
|
38
|
+
# the following line have the same effect
|
39
|
+
#samao.from 'https://github.com/Lax?tab=repositories'
|
40
|
+
|
41
|
+
# tell samao how to find the next page
|
42
|
+
samao.find :next, 'div.pagination a.next_page'
|
43
|
+
samao.max_page 1
|
44
|
+
|
45
|
+
# tell samao how to find items.
|
46
|
+
# further more, set the data from matched HTML node/element.
|
47
|
+
samao.find_item 'div#user-repositories-list li a[itemprop="name codeRepository"]' do |item|
|
48
|
+
item.set_url :url, item.raw(:item)['href']
|
49
|
+
item.set :title, item.raw(:item).text.strip
|
50
|
+
end
|
51
|
+
|
52
|
+
samao.find_item 'div#user-repositories-list li' do |item|
|
53
|
+
item.find(:url, 'a[itemprop="name codeRepository"]') {|value| [:set_url, :url, value.first['href']] }
|
54
|
+
item.find(:title, 'a[itemprop="name codeRepository"]') {|value| [:set, value.first.text.strip] }
|
55
|
+
end
|
56
|
+
|
57
|
+
# if it need to open content page for more information
|
58
|
+
# default key is :url
|
59
|
+
samao.add_detail :url do |detail|
|
60
|
+
#samao.add_detail do |detail|
|
61
|
+
detail.find(:author, 'h1.public .author a') {|value| value.first.text.strip }
|
62
|
+
end
|
63
|
+
|
64
|
+
# run the detector
|
65
|
+
samao.run
|
66
|
+
|
67
|
+
# read items
|
68
|
+
p samao.items
|
69
|
+
## [{:url=>"https://github.com/Lax/awesome", :title=>"awesome", :author=>"Lax"}, {:url=>"https://github.com/Lax/lax.github.com", :title=>"lax.github.com", :author=>"Lax"}, ..]
|
70
|
+
```
|
66
71
|
|
67
72
|
## Development
|
68
73
|
|
data/lib/samao/detector.rb
CHANGED
@@ -113,12 +113,13 @@ module Samao
|
|
113
113
|
self
|
114
114
|
end
|
115
115
|
|
116
|
-
# set max
|
117
|
-
def
|
118
|
-
@
|
116
|
+
# set max concurrent level
|
117
|
+
def max_concurrent(max)
|
118
|
+
@max_concurrent = max
|
119
119
|
|
120
120
|
self
|
121
121
|
end
|
122
|
+
alias :concurrent :max_concurrent
|
122
123
|
|
123
124
|
# get pages
|
124
125
|
def pages
|
data/lib/samao/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samao
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Lantao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|