Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
fixing bug w/ twitter_connect (using wrong var name). adding ability …
Browse files Browse the repository at this point in the history
…to follow a twitter account on app auth.
  • Loading branch information
gleuch committed Oct 3, 2009
1 parent 5225a1b commit 798ac47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions retweet.rb
Expand Up @@ -19,7 +19,7 @@


helpers do helpers do
def twitter_connect(user={}) def twitter_connect(user={})
@twitter_client = TwitterOAuth::Client.new(:consumer_key => configatron.twitter_oauth_token, :consumer_secret => configatron.twitter_oauth_secret, :token => (!@user.blank? ? user.oauth_token : nil), :secret => (!@user.blank? ? user.oauth_secret : nil)) rescue nil @twitter_client = TwitterOAuth::Client.new(:consumer_key => configatron.twitter_oauth_token, :consumer_secret => configatron.twitter_oauth_secret, :token => (!user.blank? ? user.oauth_token : nil), :secret => (!user.blank? ? user.oauth_secret : nil)) rescue nil
end end


def twitter_fail(msg=false) def twitter_fail(msg=false)
Expand All @@ -38,15 +38,15 @@ def launch_retweet_hell


@base_users.each do |user| @base_users.each do |user|
twitter_connect(user) twitter_connect(user)
STDERR.puts "Loading #{user.screen_name}..."
unless @twitter_client.blank? unless @twitter_client.blank?
info = @twitter_client.info rescue nil info = @twitter_client.info rescue nil
STDERR.puts "Their tweet: \"#{info}\"" STDERR.puts "Their tweet: \"#{info}\""

if !info.blank? && !info['status'].blank? && !info['status']['text'].blank? if !info.blank? && !info['status'].blank? && !info['status']['text'].blank?
retweet = "RT: @#{info['screen_name']}: %s #{configatron.twitter_hashtag}" retweet = "RT: @#{info['screen_name']}: %s #{configatron.twitter_hashtag}"
retweet = retweet.gsub(/\%s/, (info['status']['text'])[0, (142-retweet.length) ]) retweet = retweet.gsub(/\%s/, (info['status']['text'])[0, (142-retweet.length) ])

@tweet = Tweet.create(:account_id => user.account_id, :tweet_id => info['status']['id'], :tweet => info['status']['text'], :retweet => retweet, :sent_at => Time.now) @tweet = Tweet.create(:account_id => user.account_id, :tweet_id => info['status']['id'], :tweet => info['status']['text'], :retweet => retweet, :sent_at => Time.now)
break break
end end
Expand All @@ -59,25 +59,25 @@ def launch_retweet_hell
unless @tweet.blank? unless @tweet.blank?
total = (User.count * (configatron.twitter_retweet_percent/100.to_f)).round total = (User.count * (configatron.twitter_retweet_percent/100.to_f)).round
total = configatron.twitter_retweet_max if total > configatron.twitter_retweet_max total = configatron.twitter_retweet_max if total > configatron.twitter_retweet_max

@users = User.find_by_sql("SELECT id, account_id, screen_name, oauth_token, oauth_secret FROM users WHERE account_id!=#{@tweet.account_id} AND active=1 ORDER BY #{rand} LIMIT #{total}") @users = User.find_by_sql("SELECT id, account_id, screen_name, oauth_token, oauth_secret FROM users WHERE account_id!=#{@tweet.account_id} AND active=1 ORDER BY #{rand} LIMIT #{total}")
@users.each do |user| @users.each do |user|
twitter_connect(user) twitter_connect(user)
unless @twitter_client.blank? unless @twitter_client.blank?

# Use Twitter Retweet API # Use Twitter Retweet API
if configatron.use_retweet_api if configatron.use_retweet_api
@twitter_client.retweet(@tweet.tweet_id) @twitter_client.retweet(@tweet.tweet_id)
# Retweet through standard method. # Retweet through standard method.
else else
@twitter_client.update(@tweet.retweet) @twitter_client.update(@tweet.retweet)
end end

# Also auto-follow retweeted user. (idea by Patrick Ewing -- http://github.com/hoverbird) # Also auto-follow retweeted user. (idea by Patrick Ewing -- http://github.com/hoverbird)
if configatron.allow_user_follow && !@twitter_client.exists?(user.account_id, @tweet.account_id) if configatron.allow_user_follow && !@twitter_client.exists?(user.account_id, @tweet.account_id)
@twitter_client.friend(@tweet.account_id) @twitter_client.friend(@tweet.account_id)
end end

else else
# Fucking get rid of the user if they don't validate... # Fucking get rid of the user if they don't validate...
user.destroy user.destroy
Expand Down Expand Up @@ -142,6 +142,7 @@ def launch_retweet_hell
begin begin
twitter_connect(@user) twitter_connect(@user)
@twitter_client.update("#{twitter_sync_tweet} #{twiter_hashtag}") @twitter_client.update("#{twitter_sync_tweet} #{twiter_hashtag}")
@twitter_client.friend(configatron.twitter_screen_name)
rescue rescue
twitter_fail('An error has occured while trying to post a tweet to Twitter. Please try again.') twitter_fail('An error has occured while trying to post a tweet to Twitter. Please try again.')
end end
Expand Down
1 change: 1 addition & 0 deletions settings.yml.default
Expand Up @@ -6,6 +6,7 @@ development: &local
twitter_oauth_token: ENTER-YOUR-TOKEN-HERE twitter_oauth_token: ENTER-YOUR-TOKEN-HERE
twitter_oauth_secret: ENTER-YOUR-TOKEN-SECRET-HERE twitter_oauth_secret: ENTER-YOUR-TOKEN-SECRET-HERE


twitter_screen_name: retweetgame
twitter_sync_tweet: 'I am now using Retweet Game by @fffffat & @gleuch. http://bit.ly/rtgame' twitter_sync_tweet: 'I am now using Retweet Game by @fffffat & @gleuch. http://bit.ly/rtgame'
twitter_hashtag: '#rtgame' twitter_hashtag: '#rtgame'


Expand Down

0 comments on commit 798ac47

Please sign in to comment.