Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

dealing with failed twitter connections - fixing the failwhale bug.

  • Loading branch information...
commit 5a25be3e74dd542daa29c26e218aaf736deae8e8 1 parent 55b4390
Sven Kräuter 5v3n authored
Showing with 33 additions and 26 deletions.
  1. +1 −1  Rakefile
  2. +32 −25 lib/tweetlr.rb
2  Rakefile
View
@@ -7,7 +7,7 @@ require 'rake/testtask'
spec = Gem::Specification.new do |s|
s.name = 'tweetlr'
- s.version = '0.0.8'
+ s.version = '0.0.9'
s.has_rdoc = true
s.extra_rdoc_files = ['README.md', 'LICENSE']
s.summary = %{tweetlr crawls twitter for a given term, extracts photos out of the collected tweets' short urls and posts the images to tumblr.}
57 lib/tweetlr.rb
View
@@ -42,7 +42,7 @@ def initialize(email, password, cookie=nil, since_id=nil, term=nil, config_file)
end
end
-
+ #post a tumblr photo entry. required arguments are :type, :date, :source, :caption, :state
def post_to_tumblr(options={})
if options[:type] && options[:date] && options[:source] && options[:caption] && options[:state]
response = Curl::Easy.http_post("#{@api_endpoint_tumblr}/api/write",
@@ -58,6 +58,29 @@ def post_to_tumblr(options={})
end
response
end
+
+ #generate the data for a tumblr photo entry by parsing a tweet
+ def generate_tumblr_photo_post tweet
+ tumblr_post = nil
+ message = tweet['text']
+ if message && !message.index('RT @') #discard retweets
+ #@log.debug "tweet: #{tweet}"
+ #puts "tweet: #{tweet}"
+ tumblr_post = {}
+ tumblr_post[:type] = 'photo'
+ tumblr_post[:date] = tweet['created_at']
+ tumblr_post[:source] = extract_image_url tweet
+ user = tweet['from_user']
+ if @whitelist.member? user.downcase
+ state = 'published'
+ else
+ state = 'draft'
+ end
+ tumblr_post[:state] = state
+ 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
+ end
+ tumblr_post
+ end
#fire a new search
def search_twitter()
@@ -167,35 +190,19 @@ def extract_link(tweet)
end
end
end
-
- def generate_tumblr_photo_post tweet
- tumblr_post = nil
- message = tweet['text']
- if message && !message.index('RT @') #discard retweets
- #@log.debug "tweet: #{tweet}"
- #puts "tweet: #{tweet}"
- tumblr_post = {}
- tumblr_post[:type] = 'photo'
- tumblr_post[:date] = tweet['created_at']
- tumblr_post[:source] = extract_image_url tweet
- user = tweet['from_user']
- if @whitelist.member? user.downcase
- state = 'published'
- else
- state = 'draft'
- end
- tumblr_post[:state] = state
- 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
- end
- tumblr_post
- end
private
#convenience method for curl http get calls
def http_get(request)
- res = Curl::Easy.http_get(request)
- JSON.parse res.body_str
+ begin
+ res = Curl::Easy.http_get(request)
+ JSON.parse res.body_str
+ rescue Curl::Err::ConnectionFailedError => err
+ #@log.error "Connection failed: #{err}"
+ puts "Connection failed: #{err}"
+ nil
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.