Skip to content

Commit

Permalink
Added consoles to Reply by tweet Feature (#6064)
Browse files Browse the repository at this point in the history
* Added Logs For Checking Reply By Tweet

* Added Logs
  • Loading branch information
namangupta01 authored and jywarren committed Jul 24, 2019
1 parent a468915 commit 3a96771
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 53 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ def trimmed_content?

def self.receive_tweet
comments = Comment.where.not(tweet_id: nil)
puts "==============================================================================="
puts "output 1"
puts comments.count
puts "==============================================================================="
if comments.any?
receive_tweet_using_since comments
else
Expand All @@ -347,39 +351,88 @@ def self.receive_tweet_without_using_since
tweets = Client.search(ENV["TWEET_SEARCH"]).collect do |tweet|
tweet
end
puts "=================================================================="
puts "output 2"
puts tweets
puts "=================================================================="
tweets = tweets.reverse
check_and_add_tweets tweets
tweets.each do |tweet|
puts "=========================================================="
puts "tweet text ->"
puts tweet.text
puts "=========================================================="
end
end

def self.check_and_add_tweets(tweets)
puts "============================================================"
puts "in check_and_add_tweets"
puts tweets
puts "============================================================"
tweets.each do |tweet|
puts "=========================================================="
puts "in tweet loop"
puts tweet
puts tweet.reply
puts "=========================================================="
next unless tweet.reply?

in_reply_to_tweet_id = tweet.in_reply_to_tweet_id
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
puts "in reply to id"
puts in_reply_to_tweet_id
puts in_reply_to_tweet_id.class
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
next unless in_reply_to_tweet_id.class == Integer

parent_tweet = Client.status(in_reply_to_tweet_id, tweet_mode: "extended")
parent_tweet_full_text = parent_tweet.attrs[:text] || parent_tweet.attrs[:full_text]
urls = URI.extract(parent_tweet_full_text)
node = get_node_from_urls_present(urls)
puts "=============================================================="
puts "parent tweet #{parent_tweet}"
puts "parent tweet full text -> #{parent_tweet_full_text}"
puts "urls => #{urls}"
puts "node => #{node}"
puts "node.nil? => #{node.nil?}"
puts "=============================================================="
next if node.nil?

twitter_user_name = tweet.user.screen_name
tweet_email = find_email(twitter_user_name)
users = User.where(email: tweet_email)
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
puts "twitter_user_name -> #{twitter_user_name}"
puts "tweet_email -> #{tweet_email}"
puts "users.any? -> #{users.any?}"
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
next unless users.any?

user = users.first
replied_tweet_text = tweet.text

puts "======================================================================================="
puts "username -> #{user.username}"
puts "replied_tweet_text -> #{replied_tweet_text}"
puts "tweet.truncated? -> #{tweet.truncated?}"
puts "======================================================================================="
if tweet.truncated?
replied_tweet = Client.status(tweet.id, tweet_mode: "extended")
replied_tweet_text = replied_tweet.attrs[:text] || replied_tweet.attrs[:full_text]
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
puts "replied_tweet -> #{replied_tweet}"
puts "replied_tweet_text -> #{replied_tweet_text}"
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
end
replied_tweet_text = replied_tweet_text.gsub(/@(\S+)/) { |m| "[#{m}](https://twitter.com/#{m})" }
puts "=========================================================================================="
puts "replied_tweet_text -> #{replied_tweet_text}"
puts "=========================================================================================="
replied_tweet_text = replied_tweet_text.delete('@')
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
puts "replied_tweet_text -> #{replied_tweet_text}"
puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
comment = node.add_comment(uid: user.uid, body: replied_tweet_text, comment_via: 2, tweet_id: tweet.id)
comment.notify user
end
Expand Down
2 changes: 1 addition & 1 deletion config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

ENV.each { |k, v| env(k, v) }

set :output, "#{Dir.pwd}/public/cron_log.log"
set :output, "#{Dir.pwd}/public/cron_log1.log"

# To simply print date into the log file for checking if cron job is working properly
every 1.minutes do
Expand Down

0 comments on commit 3a96771

Please sign in to comment.