<commit_before>require 'open-uri'
require 'json'

require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'

LIVE_URL = 'http://5by5.tv/live/data.json'

class Suggestion
  include DataMapper::Resource

  property :id,         Serial
  property :title,      String,   :length => 100,
    :message => "Suggestion NOT recorded. Showbot is sorry. Think title, not transcript."
  property :user,       String
  property :show,       String
  property :created_at, DateTime
  property :updated_at, DateTime

  validates_presence_of :title

  before :save, :fetch_show
  before :save, :fix_title

  # Remove quotes from the title before saving
  def fix_title
    # Remove quotes if the user thought they needed them
    self.title = self.title.gsub(/^(?:'|")(.*)(?:'|")$/, '\1')
  end

  # Set the show from data.json on 5by5 before saving
  def fetch_show
    if !self.show
      # Only fetch show from website if it wasn't set previously.
      # This is mostly for debugging
      live_hash = JSON.parse(open(LIVE_URL).read)

      if live_hash and live_hash.has_key?("live") and live_hash["live"]
        # Show is live, read show name
        broadcast = live_hash["broadcast"] if live_hash.has_key? "broadcast"
        self.show = broadcast["slug"] if broadcast.has_key? "slug"
      end
    end
  end

  def self.recent(days_ago = 1)
    from = DateTime.now - days_ago
    all(:created_at.gt => from).all(:order => [:created_at.desc])
  end
  


end<commit_msg>Updated to use the fetch_live_show_slug method from Shows<commit_after>require 'open-uri'
require 'json'

require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'

LIVE_URL = 'http://5by5.tv/live/data.json'

class Suggestion
  include DataMapper::Resource

  property :id,         Serial
  property :title,      String,   :length => 100,
    :message => "Suggestion NOT recorded. Showbot is sorry. Think title, not transcript."
  property :user,       String
  property :show,       String
  property :created_at, DateTime
  property :updated_at, DateTime

  validates_presence_of :title

  # =====================
  # Before Save
  # =====================

  before :save, :set_live_show
  before :save, :fix_title

  # Remove quotes from the title before saving
  def fix_title
    # Remove quotes if the user thought they needed them
    self.title = self.title.gsub(/^(?:'|")(.*)(?:'|")$/, '\1')
  end

  def set_live_show
    # Only fetch show from website if it wasn't set previously.
    if !self.show
      self.show = Shows.fetch_live_show_slug
    end
  end

  # =====================
  # Class Methods
  # =====================

  def self.recent(days_ago = 1)
    from = DateTime.now - days_ago
    all(:created_at.gt => from).all(:order => [:created_at.desc])
  end
  
end
{'fraction_non_alphanumeric': 0.1381055676066522, 'fraction_numerical': 0.005784526391901663, 'mean_word_length': 3.256923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '3915877', 'n_tokens_mistral': 908, 'n_tokens_neox': 873, 'n_words': 259}