tweetlr 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/bin/tweetlr +1 -1
- data/lib/tweetlr.rb +19 -5
- metadata +1 -1
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ require 'rake/testtask'
|
|
7
7
|
|
8
8
|
spec = Gem::Specification.new do |s|
|
9
9
|
s.name = 'tweetlr'
|
10
|
-
s.version = '0.0.
|
10
|
+
s.version = '0.0.8'
|
11
11
|
s.has_rdoc = true
|
12
12
|
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
13
13
|
s.summary = %{tweetlr crawls twitter for a given term, extracts photos out of the collected tweets' short urls and posts the images to tumblr.}
|
data/bin/tweetlr
CHANGED
@@ -40,7 +40,7 @@ Daemons.run_proc('tweetlr', :dir_mode => :script, :dir => './', :backtrace => tr
|
|
40
40
|
#@log.debug @tweetlr.post_to_tumblr tumblr_post
|
41
41
|
#puts "tumblr post: #{tumblr_post}"
|
42
42
|
res = @tweetlr.post_to_tumblr tumblr_post
|
43
|
-
|
43
|
+
puts "tumblr response: #{res.header_str} #{res.body_str}" unless res.response_code == 201
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/lib/tweetlr.rb
CHANGED
@@ -3,7 +3,6 @@ require 'yaml'
|
|
3
3
|
require 'curb'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
|
7
6
|
class Tweetlr
|
8
7
|
|
9
8
|
GENERATOR = %{tweetlr - http://github.com/5v3n/tweetlr}
|
@@ -80,19 +79,30 @@ class Tweetlr
|
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
83
|
-
#extract the linked image file's url
|
82
|
+
#extract the linked image file's url from a tweet
|
84
83
|
def extract_image_url(tweet)
|
85
84
|
link = extract_link tweet
|
85
|
+
find_image_url link
|
86
|
+
end
|
87
|
+
|
88
|
+
#extract the linked image file's url from a tweet
|
89
|
+
def find_image_url(link)
|
86
90
|
url = nil
|
87
|
-
if link
|
91
|
+
if !link.nil?
|
88
92
|
url = image_url_instagram link if (link.index('instagr.am') || link.index('instagram.com'))
|
89
93
|
url = image_url_picplz link if link.index 'picplz'
|
90
94
|
url = image_url_twitpic link if link.index 'twitpic'
|
91
95
|
url = image_url_yfrog link if link.index 'yfrog'
|
92
96
|
url = image_url_imgly link if link.index 'img.ly'
|
97
|
+
url = image_url_tco link if link.index 't.co'
|
93
98
|
end
|
94
99
|
url
|
95
100
|
end
|
101
|
+
|
102
|
+
def image_url_tco(link_url)
|
103
|
+
service_url = link_url_redirect link_url
|
104
|
+
find_image_url service_url
|
105
|
+
end
|
96
106
|
|
97
107
|
#find the image's url for an instagram link
|
98
108
|
def image_url_instagram(link_url)
|
@@ -127,7 +137,11 @@ class Tweetlr
|
|
127
137
|
|
128
138
|
# extract image url from services like twitpic & img.ly that do not offer oembed interfaces
|
129
139
|
def image_url_redirect(link_url, service_endpoint, stop_indicator = LOCATION_STOP_INDICATOR)
|
130
|
-
|
140
|
+
link_url_redirect "#{service_endpoint}#{extract_id link_url}", stop_indicator
|
141
|
+
end
|
142
|
+
|
143
|
+
def link_url_redirect(short_url, stop_indicator = LOCATION_STOP_INDICATOR)
|
144
|
+
resp = Curl::Easy.http_get(short_url) { |res| res.follow_location = true }
|
131
145
|
if(resp.header_str.index(LOCATION_START_INDICATOR) && resp.header_str.index(stop_indicator))
|
132
146
|
start = resp.header_str.index(LOCATION_START_INDICATOR) + LOCATION_START_INDICATOR.size
|
133
147
|
stop = resp.header_str.index(stop_indicator, start)
|
@@ -171,7 +185,7 @@ class Tweetlr
|
|
171
185
|
state = 'draft'
|
172
186
|
end
|
173
187
|
tumblr_post[:state] = state
|
174
|
-
tumblr_post[:caption] =
|
188
|
+
tumblr_post[:caption] = %?<a href="http://twitter.com/#{user}" alt="#{user}">@#{user}</a> #{@shouts}: #{tweet['text']}? #TODO make this a bigger matter of yml configuration
|
175
189
|
end
|
176
190
|
tumblr_post
|
177
191
|
end
|