diff --git a/app/models/comment.rb b/app/models/comment.rb index b4ef32d8b7..5f70247c46 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 @@ -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 diff --git a/config/schedule.rb b/config/schedule.rb index 3fb45b0ce0..2711a5a8cd 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -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