-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.rb
27 lines (21 loc) · 889 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'twitter'
require 'json'
require 'google_translate'
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_tweets = client.user_timeline('phoet')
last_tweet = client.user('idontgiveaphoet').status
last_tweets = last_tweets.select {|twit| twit.created_at > last_tweet.created_at }.reverse
last_tweets.each do |tweet|
unescaped_tweet = CGI.unescapeHTML(tweet.text)
tweet_with_love = unescaped_tweet.gsub(/@/, '❤️')
from = "de"
to = "en"
translation = GoogleTranslate.new.translate(from, to, tweet_with_love)[0][0][0]
puts "from: #{tweet_with_love} to: #{translation}"
client.update(translation[0...140], in_reply_to_status_id: tweet.id)
end