Created
September 11, 2015 06:42
-
-
Save d-sea/32022cf6c632330389f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'twitter' | |
## login ## | |
client = Twitter::REST::Client.new do |config| | |
config.consumer_key = ENV['CONSUMER_KEY'] | |
config.consumer_secret = ENV['CONSUMER_SECRET'] | |
config.access_token = ENV['ACCESS_TOKEN'] | |
config.access_token_secret = ENV['ACCESS_TOKEN_SECRET'] | |
end | |
# last since_id from a file | |
file_id = open("current.txt").readlines[0].to_i | |
file_rt = open("current.txt").readlines[1].to_i | |
file_fav = open("current.txt").readlines[2].to_i | |
# access to Twitter API | |
results = client.retweets_of_me(count: 1) | |
current_id = results[0].id | |
current_rt = results[0].retweet_count | |
current_fav = results[0].favorite_count | |
unless file_id == current_id && file_rt == current_rt && file_fav == current_fav | |
# update a file | |
f = File.open("current.txt", "w") | |
f.puts current_id | |
f.puts current_rt | |
f.puts current_fav | |
f.close | |
results.each do |tweet| | |
rt = tweet.retweet_count | |
fav = tweet.favorite_count | |
text = tweet.text[0..40] | |
if tweet.text.length > 41 | |
text += "..." | |
end | |
status_url = "https://twitter.com/" + tweet.user.screen_name + "/status/" + tweet.id.to_s | |
## Fav only ## | |
if rt == 0 && fav > 0 | |
status = fav.to_s + "Fav " + "My tweet's response: " + text + " " + status_url | |
client.update(status, in_reply_to_status_id: tweet.id) | |
puts "Post Response:" + status | |
## RT only ## | |
elsif rt > 0 && fav == 0 | |
status = rt.to_s + "RT " + "My tweet's response: " + text + " " + status_url | |
client.update(status, in_reply_to_status_id: tweet.id) | |
puts "Post Response:" + status | |
## both ## | |
elsif rt > 0 && fav > 0 | |
status = rt.to_s + "RT, " + fav.to_s + "Fav " + "My tweet's response: " + text + " " + status_url | |
client.update(status, in_reply_to_status_id: tweet.id) | |
puts "Post Response:" + status | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment