fetch_meizi 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/fetch-meizi.gemspec +1 -0
- data/lib/fetch_meizi/version.rb +1 -1
- data/lib/fetch_meizi.rb +11 -5
- data/test/fetch_meizi_test.rb +4 -0
- metadata +18 -2
data/fetch-meizi.gemspec
CHANGED
data/lib/fetch_meizi/version.rb
CHANGED
data/lib/fetch_meizi.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rss'
|
3
|
+
require 'nokogiri'
|
3
4
|
require 'open-uri'
|
4
5
|
|
5
6
|
class Meizi
|
6
7
|
|
7
|
-
URL = 'http://feed.feedsky.com/meizitu'
|
8
|
-
|
9
8
|
def self.fetch
|
10
|
-
open(
|
9
|
+
open("http://feed.feedsky.com/meizitu") do |rss|
|
11
10
|
feed = RSS::Parser.parse(rss)
|
12
11
|
feed.items.each do |item|
|
13
12
|
if item.description =~ /src=\"(\S*)\"/
|
@@ -18,6 +17,14 @@ class Meizi
|
|
18
17
|
@image_url
|
19
18
|
end
|
20
19
|
end
|
20
|
+
|
21
|
+
def self.fetch_qingchun
|
22
|
+
meizi_list = Nokogiri::HTML open("http://www.chunluoli.com/qingchun")
|
23
|
+
random_url = meizi_list.search("a.img").to_a.sample.attr("href")
|
24
|
+
|
25
|
+
meizi = Nokogiri::HTML open(random_url)
|
26
|
+
meizi.search("div.pageImg p img").attr("src").value
|
27
|
+
end
|
21
28
|
|
22
29
|
private
|
23
30
|
def self.image_url_avaliable?
|
@@ -25,5 +32,4 @@ class Meizi
|
|
25
32
|
res['content-type'].match(/image\/(jpeg|png|)/)
|
26
33
|
end
|
27
34
|
|
28
|
-
|
29
|
-
end
|
35
|
+
end
|
data/test/fetch_meizi_test.rb
CHANGED
@@ -8,6 +8,10 @@ class FetchMeiziTest < Test::Unit::TestCase
|
|
8
8
|
assert Meizi.fetch.match(/\Ahttp.*(jpeg|jpg|gif|png)\Z/)
|
9
9
|
end
|
10
10
|
|
11
|
+
def test_fetch_qingchun
|
12
|
+
assert Meizi.fetch_qingchun.match(/\Ahttp.*(jpeg|jpg|gif|png)\Z/)
|
13
|
+
end
|
14
|
+
|
11
15
|
def test_fetch_meizi_should_return_a_visiable_image
|
12
16
|
res = Net::HTTP.get_response(URI(Meizi.fetch))
|
13
17
|
assert res['content-type'].match(/image\/(jpeg|png|)/)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fetch_meizi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: nokogiri
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.5.9
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.9
|
46
62
|
description: Fetch the newest image from meizitu
|
47
63
|
email:
|
48
64
|
- zlx.star@gmail.com
|