<commit_before>class Notification
  def self.notify_favorite(tweet)
    if Settings.notification.favorites.include?(tweet.favorites.count)
      if tweet.user.registered? && tweet.user.account.active? && tweet.user.account.notification?
        reply_favs(tweet, tweet.favorites.count)
      end
    end
  end

  def self.reply_favs(tweet, count)
    Thread.new do
      url = Rails.application.routes.url_helpers.tweet_url(host: Settings.base_url, id: tweet.id)
      tweet("@#{tweet.user_screen_name} #{count}favs! #{url}", tweet.id)
    end
  end

  private
  def self.tweet(text, reply_to = 0)
    cur = Rails.cache.read("notification_account") || 0
    if Settings.notification.accounts[cur]
      begin
        client = Twitter::REST::Client.new(consumer_key: Settings.notification.consumer.key,
                                           consumer_secret: Settings.notification.consumer.secret,
                                           oauth_token: Settings.notification.accounts[cur].token,
                                           oauth_token_secret: Settings.notification.accounts[cur].secret)

        client.update(text, in_reply_to_status_id: reply_to)
      rescue Exception
        cur += 1
        doretry = true
        Rails.logger.error($!)
      end
      Rails.cache.write("notification_account", cur, expires_in: 15.minutes)
      tweet(text, reply_to) if doretry
    else
      # wait for expiring notification_account cache
      #cur = 0
    end
  end
end<commit_msg>ignore "Status is a duplicate." error<commit_after>class Notification
  def self.notify_favorite(tweet)
    if Settings.notification.favorites.include?(tweet.favorites.count)
      if tweet.user.registered? && tweet.user.account.active? && tweet.user.account.notification?
        reply_favs(tweet, tweet.favorites.count)
      end
    end
  end

  def self.reply_favs(tweet, count)
    Thread.new do
      url = Rails.application.routes.url_helpers.tweet_url(host: Settings.base_url, id: tweet.id)
      tweet("@#{tweet.user_screen_name} #{count}favs! #{url}", tweet.id)
    end
  end

  private
  def self.tweet(text, reply_to = 0)
    cur = Rails.cache.read("notification_account") || 0
    if Settings.notification.accounts[cur]
      begin
        client = Twitter::REST::Client.new(consumer_key: Settings.notification.consumer.key,
                                           consumer_secret: Settings.notification.consumer.secret,
                                           oauth_token: Settings.notification.accounts[cur].token,
                                           oauth_token_secret: Settings.notification.accounts[cur].secret)

        client.update(text, in_reply_to_status_id: reply_to)
      rescue Twitter::Error::AlreadyPosted
        # Status is a duplicate.
      rescue Exception
        cur += 1
        doretry = true
        Rails.logger.error($!)
      end
      Rails.cache.write("notification_account", cur, expires_in: 15.minutes)
      tweet(text, reply_to) if doretry
    else
      # wait for expiring notification_account cache
      #cur = 0
    end
  end
end
{'fraction_non_alphanumeric': 0.09870550161812297, 'fraction_numerical': 0.003883495145631068, 'mean_word_length': 2.453631284916201, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '742493', 'n_tokens_mistral': 939, 'n_tokens_neox': 891, 'n_words': 172}