Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@micmmakarov
Created August 15, 2012 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micmmakarov/3355673 to your computer and use it in GitHub Desktop.
Save micmmakarov/3355673 to your computer and use it in GitHub Desktop.
Find random tweet and then translate it to italian and repost
require 'twitter'
require 'google_translate'
# We using credentials of "Rails School" twitter account
Twitter.configure do |config|
# credentials here!
end
# for translator
translator = Google::Translator.new
tweets = Twitter.search("#barackobama").results
random_tweet_text = tweets.sample.text
piged_tweet = translator.translate("en", "it", random_tweet_text)[0]
hash_tags = "#international #railsschool"
message = piged_tweet.slice(0..(140 - hash_tags.size - 2))
Twitter.update("#{message} #{hash_tags}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment