<commit_before># frozen_string_literal: true
# == Schema Information
#
# Table name: twitter_tweets
#
#  id               :integer          not null, primary key
#  twitter_user_id  :integer          not null
#  user_screen_name :string           not null
#  user_name        :string           not null
#  tweet_id         :string           not null
#  text             :text             not null
#  created_at       :datetime         not null
#  updated_at       :datetime         not null
#
# Indexes
#
#  index_twitter_tweets_on_tweet_id         (tweet_id) UNIQUE
#  index_twitter_tweets_on_twitter_user_id  (twitter_user_id)
#

class TwitterTweet < ApplicationRecord
  belongs_to :twitter_user

  def notify_slack
    return unless Rails.env.production?

    webhook_url = ENV.fetch("ANNICT_SLACK_WEBHOOK_URL_FOR_NOTIFICATIONS")
    options = {
      channel: "#official_twitter",
      username: "Notifier",
      icon_emoji: ":annict:"
    }

    messages = ["\n\n---\n"]

    if twitter_user.work.present?
      messages << "<https://annict.jp/db/works/#{twitter_user.work.id}/edit|Annict DB>"
    end

    messages << url

    notifier = Slack::Notifier.new(webhook_url, options)
    notifier.ping(messages.join("\n"))
  end

  def url
    "https://twitter.com/#{user_screen_name}/status/#{tweet_id}"
  end
end<commit_msg>Update a post format (Take.3)<commit_after># frozen_string_literal: true
# == Schema Information
#
# Table name: twitter_tweets
#
#  id               :integer          not null, primary key
#  twitter_user_id  :integer          not null
#  user_screen_name :string           not null
#  user_name        :string           not null
#  tweet_id         :string           not null
#  text             :text             not null
#  created_at       :datetime         not null
#  updated_at       :datetime         not null
#
# Indexes
#
#  index_twitter_tweets_on_tweet_id         (tweet_id) UNIQUE
#  index_twitter_tweets_on_twitter_user_id  (twitter_user_id)
#

class TwitterTweet < ApplicationRecord
  belongs_to :twitter_user

  def notify_slack
    return unless Rails.env.production?

    webhook_url = ENV.fetch("ANNICT_SLACK_WEBHOOK_URL_FOR_NOTIFICATIONS")
    options = {
      channel: "#official_twitter",
      username: "Notifier",
      icon_emoji: ":annict:"
    }

    messages = [
      "#{user_name} [at]#{user_screen_name}",
      text
    ]

    link = "<#{url}|Twitter>"
    if twitter_user.work.present?
      link += " / <https://annict.jp/db/works/#{twitter_user.work.id}/edit|Annict DB>"
    end
    messages << link

    messages << "\n---\n\n"

    notifier = Slack::Notifier.new(webhook_url, options)
    notifier.ping(messages.join("\n"))
  end

  def url
    "https://twitter.com/#{user_screen_name}/status/#{tweet_id}"
  end
end
{'fraction_non_alphanumeric': 0.10556552962298026, 'fraction_numerical': 0.0003590664272890485, 'mean_word_length': 2.478152309612984, 'pattern_counts': {'":': 2, '<': 16, '<?xml version=': 0, '>': 6, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7028888', 'n_tokens_mistral': 942, 'n_tokens_neox': 916, 'n_words': 183}