twitter-photos 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/twitter-photos.rb +67 -62
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/lib/twitter-photos.rb
CHANGED
@@ -5,17 +5,16 @@ class TwitterPhoto
|
|
5
5
|
attr_accessor :username, :thumb, :date, :tweet, :url
|
6
6
|
|
7
7
|
TWITPIC_URL = 'http://twitpic.com'
|
8
|
-
TWEETPHOTO_URL = 'http://tweetphotoapi.com/api/tpapi.svc/json/
|
8
|
+
TWEETPHOTO_URL = 'http://tweetphotoapi.com/api/tpapi.svc/json/users/'
|
9
9
|
YFROG_URL = 'http://yfrog.com/froggy.php'
|
10
|
-
TWITGOO_URL = 'http://twitgoo.com/api/
|
10
|
+
TWITGOO_URL = 'http://twitgoo.com/api/user/timeline/'
|
11
11
|
|
12
12
|
|
13
13
|
def initialize(thumb=nil, tweet='No tweet for this photo', date=nil, url=nil, username=nil)
|
14
|
-
date = date.strip
|
15
14
|
dmatch = date.match(/\sago\b/i)
|
16
15
|
@username = username
|
17
16
|
@thumb = thumb
|
18
|
-
@tweet = tweet
|
17
|
+
@tweet = tweet
|
19
18
|
@date = dmatch.nil? ? DateTime.parse(date).to_s : DateTime.time_ago_to_date(date).to_s rescue @date = date
|
20
19
|
@url = url
|
21
20
|
@tweet = "No tweet for this photo." if @tweet.blank?
|
@@ -40,67 +39,73 @@ class TwitterPhoto
|
|
40
39
|
# Fetch photos from Twitpic, yFrog, Twitgoo, and TweetPhoto.
|
41
40
|
#
|
42
41
|
# @example Find photos by @bookis only from yfrog and twitpic
|
43
|
-
# TwitterPhoto.get_photos_by('bookis', :tweetphoto => false, :yfrog => true, :twitpic => true, :twitgoo => false)
|
42
|
+
# TwitterPhoto.get_photos_by('bookis', :page => 2, :tweetphoto => false, :yfrog => true, :twitpic => true, :twitgoo => false)
|
44
43
|
#
|
45
44
|
# @option options [true, false] :tweetphoto
|
46
45
|
# @option options [true, false] :twitpic
|
47
46
|
# @option options [true, false] :yfrog
|
48
47
|
# @option options [true, false] :twitgoo
|
48
|
+
# @option options [Integer] :page
|
49
49
|
#
|
50
50
|
# @return [TwitterPhoto] collection.
|
51
51
|
# @param [String] username
|
52
52
|
# Accepts any twitter username
|
53
53
|
# @param [Hash] options
|
54
54
|
# exclude photo services (optional)
|
55
|
-
|
55
|
+
# select number of pages to collect, defaults to 1
|
56
|
+
def self.get_photos_by(username, options={:twitpic => true, :yfrog => true, :tweetphoto => true, :twitgoo => true, :page => 1})
|
56
57
|
TwitterPhoto.delete_all
|
57
58
|
hydra = Typhoeus::Hydra.new
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
59
|
+
1.upto(options[:page]).each do |page_num|
|
60
|
+
twitpic_request = Typhoeus::Request.new("#{TWITPIC_URL}/photos/#{username}", :params => {:page => page_num}, :timeout => 5000)
|
61
|
+
twitpic_request.on_complete do |response|
|
62
|
+
twitpics = Nokogiri.parse(response.body)
|
63
|
+
twitpics.xpath("//div[@class='profile-photo-img']/a").each do |row|
|
64
|
+
url = row[:href]
|
65
|
+
twitpic_requests = Typhoeus::Request.new("#{TWITPIC_URL}#{url}", :timeout => 5000)
|
66
|
+
twitpic_requests.on_complete do |twitpic|
|
67
|
+
begin
|
68
|
+
twitpic = Nokogiri.parse(twitpic.body)
|
69
|
+
# pic = []
|
70
|
+
TwitterPhoto.new(
|
71
|
+
"#{TWITPIC_URL}/show/thumb#{url}.jpg",
|
72
|
+
twitpic.xpath("//div/div[@id='view-photo-caption']").text,
|
73
|
+
twitpic.xpath("//div/div[@id='photo-info']").text,
|
74
|
+
twitpic.at_xpath("//img[@class='photo']")[:src],
|
75
|
+
username
|
76
|
+
)
|
77
|
+
rescue
|
78
|
+
end
|
77
79
|
end
|
80
|
+
hydra.queue twitpic_requests
|
78
81
|
end
|
79
|
-
hydra.queue twitpic_request
|
80
82
|
end
|
83
|
+
hydra.queue twitpic_request unless options[:twitpic] == false
|
81
84
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
85
|
+
1.upto(options[:page]).each do |page_num|
|
86
|
+
yfrog_request = Typhoeus::Request.new(YFROG_URL, :params => {:page => page_num, :username => username}, :timeout => 5000)
|
87
|
+
yfrog_request.on_complete do |response|
|
88
|
+
yfrogs = Nokogiri.parse(response.body)
|
89
|
+
yfrogs.xpath("//div[@class='timeline_entry']").each do |row|
|
90
|
+
url = row.at_xpath("div/div[@class='thumbtweet' ]/a")[:href]
|
91
|
+
yfrog_requests = Typhoeus::Request.new(url, :timeout => 5000)
|
92
|
+
yfrog_requests.on_complete do |yfrog|
|
93
|
+
begin
|
94
|
+
yfrog = Nokogiri.parse(yfrog.body)
|
95
|
+
TwitterPhoto.new(
|
96
|
+
yfrog.at_xpath("//meta[@property='og:title']").attributes['content'].to_s + '.th.jpg',
|
97
|
+
yfrog.at_xpath("///div[@class='twittertweet']/div/div/div").text,
|
98
|
+
yfrog.at_xpath("///div[@class='twittertweet']/div/div/div/div").text,
|
99
|
+
yfrog.at_xpath("//img[@id='main_image']")[:src],
|
100
|
+
username
|
101
|
+
)
|
99
102
|
rescue
|
100
103
|
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
+
end
|
105
|
+
hydra.queue yfrog_requests
|
106
|
+
end
|
107
|
+
end
|
108
|
+
hydra.queue yfrog_request unless options[:yfrog] == false
|
104
109
|
end
|
105
110
|
|
106
111
|
tweetphoto_request = Typhoeus::Request.new("#{TWEETPHOTO_URL}#{username}", :timeout => 5000)
|
@@ -123,27 +128,27 @@ class TwitterPhoto
|
|
123
128
|
hydra.queue tweetphoto_username_request
|
124
129
|
end
|
125
130
|
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
131
|
+
|
132
|
+
1.upto(options[:page]).each do |page_num|
|
133
|
+
twitgoo_request = Typhoeus::Request.new("#{TWITGOO_URL}#{username}", :params => {:page => page_num, :format => 'json'}, :timeout => 5000)
|
134
|
+
twitgoo_request.on_complete do |response|
|
135
|
+
if response.code == 200
|
136
|
+
twitgoo = JSON.parse(response.body)
|
137
|
+
twitgoo['media'].each do |twit|
|
138
|
+
TwitterPhoto.new(
|
139
|
+
twit['thumburl'],
|
140
|
+
twit['text'],
|
141
|
+
twit['created_at'],
|
142
|
+
twit['imageurl'],
|
143
|
+
username
|
144
|
+
)
|
145
|
+
end
|
139
146
|
end
|
140
147
|
end
|
148
|
+
hydra.queue twitgoo_request unless options[:twitgoo] == false
|
141
149
|
end
|
142
150
|
|
143
|
-
hydra.queue yfrog_request unless options[:yfrog] == false
|
144
151
|
hydra.queue tweetphoto_request unless options[:tweetphoto] == false
|
145
|
-
hydra.queue twitpic_request unless options[:twitpic] == false
|
146
|
-
hydra.queue twitgoo_request unless options[:twitgoo] == false
|
147
152
|
hydra.run
|
148
153
|
|
149
154
|
TwitterPhoto.find_by_username(username)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- bookis
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-02 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|