mmimage 0.0.1
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/bin/down +4 -0
- data/lib/download.rb +43 -0
- metadata +49 -0
data/bin/down
ADDED
data/lib/download.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
#========================================================================
|
|
4
|
+
# FileName: app.rb
|
|
5
|
+
# Author: Linxiangyu
|
|
6
|
+
# Email: lxyweb@gmail.com
|
|
7
|
+
# HomePage: http://www.linxiangyu.org
|
|
8
|
+
# LastChange: 2012-10-18 22:12:06
|
|
9
|
+
#========================================================================
|
|
10
|
+
require "nokogiri"
|
|
11
|
+
require "open-uri"
|
|
12
|
+
|
|
13
|
+
class MMImage
|
|
14
|
+
|
|
15
|
+
attr_accessor :down_image
|
|
16
|
+
|
|
17
|
+
def self.download_file(file_name, url)
|
|
18
|
+
begin
|
|
19
|
+
puts " Downlanding #{file_name}"
|
|
20
|
+
date = open(url).read
|
|
21
|
+
file = File.new file_name, 'w'
|
|
22
|
+
file << date
|
|
23
|
+
file.flush
|
|
24
|
+
file.close
|
|
25
|
+
rescue => e
|
|
26
|
+
puts "Hello, I'm a error: #{e}"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def self.down_image(url)
|
|
32
|
+
doc = Nokogiri::HTML(open(url))
|
|
33
|
+
select = 'img'
|
|
34
|
+
doc.css(select).each do |img|
|
|
35
|
+
img_url = img['src']
|
|
36
|
+
name = Time.now.to_f.to_s + File.extname(img_url)
|
|
37
|
+
download_file(name, img_url)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
MMImage.down_image("http://jandan.net/")
|
|
43
|
+
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mmimage
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Lin Xiangyu
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-10-10 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: A image downloader by mmclub
|
|
15
|
+
email: lxyweb@gmail.com
|
|
16
|
+
executables:
|
|
17
|
+
- down
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- lib/download.rb
|
|
22
|
+
- !binary |-
|
|
23
|
+
YmluL2Rvd24=
|
|
24
|
+
homepage: http://linxiangyu.info
|
|
25
|
+
licenses: []
|
|
26
|
+
post_install_message:
|
|
27
|
+
rdoc_options: []
|
|
28
|
+
require_paths:
|
|
29
|
+
- lib
|
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
|
+
none: false
|
|
32
|
+
requirements:
|
|
33
|
+
- - ! '>='
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '0'
|
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
|
+
none: false
|
|
38
|
+
requirements:
|
|
39
|
+
- - ! '>='
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
requirements: []
|
|
43
|
+
rubyforge_project:
|
|
44
|
+
rubygems_version: 1.8.23
|
|
45
|
+
signing_key:
|
|
46
|
+
specification_version: 3
|
|
47
|
+
summary: A image downloader
|
|
48
|
+
test_files: []
|
|
49
|
+
has_rdoc:
|