little_fish 0.0.1 → 0.0.2
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.md +24 -10
- data/lib/little_fish/fisher.rb +20 -4
- data/lib/little_fish/runner.rb +1 -0
- data/lib/little_fish/version.rb +1 -1
- metadata +8 -8
data/README.md
CHANGED
@@ -3,12 +3,17 @@
|
|
3
3
|
This gem is a little tool for pulling infomation from boston bigpicture, which is a news site with beautiful photos.
|
4
4
|
The reutrn info format is a data sructure looks like:
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
```ruby
|
7
|
+
bp_info{
|
8
|
+
:total_desc => "description for the whole theme of all photos"
|
9
|
+
:image_list => [
|
10
|
+
image{
|
11
|
+
:url => url
|
12
|
+
:desc => "description for the single photo"
|
13
|
+
}
|
14
|
+
]#list of photos
|
15
|
+
}
|
16
|
+
```
|
12
17
|
|
13
18
|
## Installation
|
14
19
|
|
@@ -25,11 +30,18 @@ Or install it yourself as:
|
|
25
30
|
$ gem install little_fish
|
26
31
|
|
27
32
|
## Usage
|
28
|
-
|
29
|
-
|
33
|
+
There are two use scenarios
|
34
|
+
|
35
|
+
1. command line application
|
36
|
+
usually you can just type:
|
37
|
+
little_fish
|
38
|
+
for downdoading:
|
39
|
+
little_fish -d
|
40
|
+
more details plz dont be hesitated to call for help
|
41
|
+
little_fish --help
|
30
42
|
|
31
|
-
2.
|
32
|
-
|
43
|
+
2. usage in your application
|
44
|
+
|
33
45
|
```ruby
|
34
46
|
require 'little_fish'
|
35
47
|
fisher = LittleFish::Fisher.new do |f|
|
@@ -37,6 +49,8 @@ fisher = LittleFish::Fisher.new do |f|
|
|
37
49
|
f.dumpfile = 'temp.txt'#if not assigned, filename will be named by datetime. if assigned 'no', 'none', or 'false', it wont dump out any file
|
38
50
|
end
|
39
51
|
info = fisher.pull
|
52
|
+
|
53
|
+
urls = info[:images].map{|e| e[:url]} #to get the urls
|
40
54
|
```
|
41
55
|
|
42
56
|
## Contributing
|
data/lib/little_fish/fisher.rb
CHANGED
@@ -3,10 +3,11 @@ require 'rss/2.0'
|
|
3
3
|
require 'nokogiri'
|
4
4
|
require 'open-uri'
|
5
5
|
require 'timeout'
|
6
|
+
require 'net/http'
|
6
7
|
|
7
8
|
module LittleFish
|
8
9
|
class Fisher
|
9
|
-
attr_accessor :url, :last_nth_item, :dumpfile
|
10
|
+
attr_accessor :url, :last_nth_item, :dumpfile, :download
|
10
11
|
def initialize
|
11
12
|
if block_given?
|
12
13
|
yield self
|
@@ -14,6 +15,7 @@ module LittleFish
|
|
14
15
|
@url = 'http://feeds.boston.com/boston/bigpicture/index'
|
15
16
|
@last_nth_item = 0
|
16
17
|
@dumpfile = './pic_output_' + Time.now.strftime('%H-%M-%S') + '.txt'
|
18
|
+
@download = false
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -30,12 +32,19 @@ module LittleFish
|
|
30
32
|
unless ['none', 'NONE', 'no', 'NO', 'false', 'FALSE'].include? @dumpfile
|
31
33
|
info 'dumping bp_info ... '
|
32
34
|
f = File.new(@dumpfile, 'w')
|
33
|
-
bp_info[:images].each do |
|
34
|
-
f.puts
|
35
|
+
bp_info[:images].each do |img|
|
36
|
+
f.puts img
|
35
37
|
end
|
36
38
|
info 'saved info in ' + @dumpfile
|
37
39
|
end
|
38
40
|
|
41
|
+
if @download
|
42
|
+
info 'down loading photos ... '
|
43
|
+
urls = bp_info[:images].map{|img| img[:url]}
|
44
|
+
download(urls, 'lf_download')
|
45
|
+
info 'photos downloaded!'
|
46
|
+
end
|
47
|
+
|
39
48
|
bp_info
|
40
49
|
end
|
41
50
|
|
@@ -105,10 +114,17 @@ module LittleFish
|
|
105
114
|
both.each do |e|
|
106
115
|
img_url = e.children[1].attributes['src'].value
|
107
116
|
img_info = e.children.last.content
|
108
|
-
img_list << { img_url => img_info }
|
117
|
+
img_list << { :url =>img_url, :desc => img_info }
|
109
118
|
end
|
110
119
|
bp_info[:images] = img_list
|
111
120
|
bp_info
|
112
121
|
end
|
122
|
+
|
123
|
+
def download (urls, dir)
|
124
|
+
Dir.mkdir(dir) unless Dir.exists? dir
|
125
|
+
urls.each do |url|
|
126
|
+
`wget -c #{url} -P #{dir}`
|
127
|
+
end
|
128
|
+
end
|
113
129
|
end
|
114
130
|
end
|
data/lib/little_fish/runner.rb
CHANGED
@@ -17,6 +17,7 @@ module LittleFish
|
|
17
17
|
def parse_options
|
18
18
|
options = OptionParser.new
|
19
19
|
options.banner = "Usage: littlefish [options]"
|
20
|
+
options.on('-d', '--download', "Download all photos after pulling" ) { @demo.download = true }
|
20
21
|
options.on('-f', '--file FILENAME', "Dumping info into file name by datetime in current directory. NOTE: use '-f no', '-f none', or '-f false' will disable dumping into any file") { |filename| @demo.dumpfile = filename }
|
21
22
|
options.on('-n', '--number NUM', "Pull last x th item by given num") { |n| @demo.last_nth_item = n.to_i }
|
22
23
|
options.on('-u', '--url URL', "Redirect the url") { |url| @demo.url = url }
|
data/lib/little_fish/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: little_fish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-05-
|
12
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70173751263660 !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: *70173751263660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70173751263240 !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: *70173751263240
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &70173751262820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70173751262820
|
47
47
|
description: my first toy gem
|
48
48
|
email:
|
49
49
|
- athom@126.com
|