<commit_before>#!/usr/bin/env ruby
require 'net/http'
require 'json'


class ScreenshotUpdater
  #Uses https://circleci.com/docs/api
  CIRCLE_BASE_URI = "https://circleci.com/api/v1/project/Factlink/core/"

  def local_repo_path
    @local_repo_path ||= begin
      File.dirname(__FILE__) + '/..'
    end
  end

  def local_screenshot_path
    local_repo_path + '/spec/screenshots/screenshots/'
  end


  def ci_current_branch_builds_uri
    URI.parse("#{CIRCLE_BASE_URI}tree/#{URI.escape(current_git_branch)}#{circle_token_query}")
  end

  def circle_token_query
    "?circle-token=#{circle_token}"
  end

  def circle_token
    @circle_token ||= begin
      ENV['CIRCLE_CI_TOKEN'] or
        fail '''
          ENV variable CIRCLE_CI_TOKEN is missing.
          You should create an api token @ https://circleci.com/account/api and
          insert it in your .bashrc (or equivalent).  For example:
          export CIRCLE_CI_TOKEN="<your-40-char-hexadecimal-token>"
        '''
    end
  end

  def current_git_branch
    `git symbolic-ref HEAD`.sub(/^refs\/heads\//,'').strip
  end

  # HTTP helpers:
  def get_json(uri)
    JSON.parse(make_http_request(uri, Net::HTTP::Get))
  end

  def make_http_request(uri, requestClass)
    while true
      request = requestClass.new uri
      response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
        http.request request
      end
      if %w(301 302).include? response.code
        uri = URI.parse(response['location'])
      elsif response.code == '200'
        break
      else
        raise "Failed to request #{uri}; response code #{response.code}"
      end
    end
    response.body
  end
end

<commit_msg>Add artifact api uri<commit_after>#!/usr/bin/env ruby
require 'net/http'
require 'json'


class ScreenshotUpdater
  #Uses https://circleci.com/docs/api
  CIRCLE_BASE_URI = "https://circleci.com/api/v1/project/Factlink/core/"

  def local_repo_path
    @local_repo_path ||= begin
      File.dirname(__FILE__) + '/..'
    end
  end

  def local_screenshot_path
    local_repo_path + '/spec/screenshots/screenshots/'
  end

  def ci_artifacts_uri(build_num)
    URI.parse("#{CIRCLE_BASE_URI}#{build_num}/artifacts#{circle_token_query}")
  end

  def ci_current_branch_builds_uri
    URI.parse("#{CIRCLE_BASE_URI}tree/#{URI.escape(current_git_branch)}#{circle_token_query}")
  end

  def circle_token_query
    "?circle-token=#{circle_token}"
  end

  def circle_token
    @circle_token ||= begin
      ENV['CIRCLE_CI_TOKEN'] or
        fail '''
          ENV variable CIRCLE_CI_TOKEN is missing.
          You should create an api token @ https://circleci.com/account/api and
          insert it in your .bashrc (or equivalent).  For example:
          export CIRCLE_CI_TOKEN="<your-40-char-hexadecimal-token>"
        '''
    end
  end

  def current_git_branch
    `git symbolic-ref HEAD`.sub(/^refs\/heads\//,'').strip
  end

  # HTTP helpers:
  def get_json(uri)
    JSON.parse(make_http_request(uri, Net::HTTP::Get))
  end

  def make_http_request(uri, requestClass)
    while true
      request = requestClass.new uri
      response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
        http.request request
      end
      if %w(301 302).include? response.code
        uri = URI.parse(response['location'])
      elsif response.code == '200'
        break
      else
        raise "Failed to request #{uri}; response code #{response.code}"
      end
    end
    response.body
  end
end


{'fraction_non_alphanumeric': 0.1180634201585504, 'fraction_numerical': 0.006795016987542469, 'mean_word_length': 2.9255555555555555, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, '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': '5261441', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1177, 'n_words': 249}