<commit_before>require 'pink_spider'
class Playlist < Enclosure
  def get_content
    PinkSpider.new.fetch_playlist(id)
  end

  def fetch_content
    @content = get_content
  end

  def title
    fetch_content if @content.nil?
    "#{@content["title"]} / #{@content["owner_name"]}"
  end

  def permalink_url provider, identifier
    fetch_content if @content.nil?
    @content["url"]
  end

  def is_active
    @content['velocity'] > 0
  end

  def activate
    self.class.update_content(id, { velocity: 10.0 })
  end

  def deactivate
    self.class.update_content(id, { velocity: 0.0 })
  end

  def fetch_tracks
    playlist_tracks = PinkSpider.new.fetch_tracks_of_playlist(id, updated_at)

    playlist_tracks["items"].map do |playlist_track|
      track_content = playlist_track["track"]
      Track.find_or_create_by_content(track_content)
      pt = Pick.find_or_create_by(enclosure_id:   playlist_track["track_id"],
                                  enclosure_type: Track.name,
                                  container_id:   playlist_track["playlist_id"],
                                  container_type: Playlist.name) do |m|
        m.created_at = playlist_track["created_at"]
        m.updated_at = playlist_track["updated_at"]
      end
      pt.save
      pt
    end
  end

  def self.fetch_actives
    contents  = PinkSpider.new.fetch_active_playlists()
    contents["items"].map do |c|
      Playlist.find_or_create_by_content(c)
    end
  end

  def self.crawl
    playlists = Playlist.fetch_actives()
    info = {
      total_playlists: playlists.count,
      total_tracks:    0,
    }
    playlists.each do |playlist|
      tracks = playlist.fetch_tracks()
      info = info.merge({
                          total_tracks: info[:total_tracks] + tracks.count
                        })
    end
    info
  end
end
<commit_msg>Update updated_at of a pick during playlist crawl<commit_after>require 'pink_spider'
class Playlist < Enclosure
  def get_content
    PinkSpider.new.fetch_playlist(id)
  end

  def fetch_content
    @content = get_content
  end

  def title
    fetch_content if @content.nil?
    "#{@content["title"]} / #{@content["owner_name"]}"
  end

  def permalink_url provider, identifier
    fetch_content if @content.nil?
    @content["url"]
  end

  def is_active
    @content['velocity'] > 0
  end

  def activate
    self.class.update_content(id, { velocity: 10.0 })
  end

  def deactivate
    self.class.update_content(id, { velocity: 0.0 })
  end

  def fetch_tracks
    playlist_tracks = PinkSpider.new.fetch_tracks_of_playlist(id, updated_at)

    playlist_tracks["items"].map do |playlist_track|
      track_content = playlist_track["track"]
      Track.find_or_create_by_content(track_content)
      pt = Pick.find_or_create_by(enclosure_id:   playlist_track["track_id"],
                                  enclosure_type: Track.name,
                                  container_id:   playlist_track["playlist_id"],
                                  container_type: Playlist.name) do |m|
        m.created_at = playlist_track["created_at"]
        m.updated_at = playlist_track["updated_at"]
      end
      pt.touch
      pt.save
      pt
    end
  end

  def self.fetch_actives
    contents  = PinkSpider.new.fetch_active_playlists()
    contents["items"].map do |c|
      Playlist.find_or_create_by_content(c)
    end
  end

  def self.crawl
    playlists = Playlist.fetch_actives()
    info = {
      total_playlists: playlists.count,
      total_tracks:    0,
    }
    playlists.each do |playlist|
      tracks = playlist.fetch_tracks()
      info = info.merge({
                          total_tracks: info[:total_tracks] + tracks.count
                        })
    end
    info
  end
end

{'fraction_non_alphanumeric': 0.09207365892714171, 'fraction_numerical': 0.0037363223912463303, 'mean_word_length': 2.401088929219601, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3476522', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1187, 'n_words': 232}