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

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

  def run
    system "cd #{local_screenshot_path}"
    get_lastest_screenshot_uris.each do |screenshot_uri|
      filename = local_filename_from_uri(screenshot_uri)

      system "curl -o #{filename} #{screenshot_uri}"
    end
  end

  def local_filename_from_uri uri
    File.basename(URI.parse(uri).path)
  end

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

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

  def get_lastest_screenshot_uris
    build_num = get_latest_build_num
    screenshot_infos =
        get_json(ci_artifacts_uri(build_num))
        .select{|artifact| artifact['pretty_path'].match(/^\$CIRCLE_ARTIFACTS\/capybara_output\//)}
    screenshot_infos
      .map{|artifact| artifact['url'] + circle_token_query}
  end

  def get_latest_build_num
    recent_builds = get_recent_builds
    raise "No branch #{current_git_branch} found." unless recent_builds && recent_builds[0]<commit_msg>Another fix for cd/curl on OS X<commit_after>#!/usr/bin/env ruby
require 'net/http'
require 'json'
require 'cgi'

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

  def run
    get_lastest_screenshot_uris.each do |screenshot_uri|
      filename = local_screenshot_path + local_filename_from_uri(screenshot_uri)

      system "curl -o #{filename} #{screenshot_uri}"
    end
  end

  def local_filename_from_uri uri
    File.basename(URI.parse(uri).path)
  end

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

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

  def get_lastest_screenshot_uris
    build_num = get_latest_build_num
    screenshot_infos =
        get_json(ci_artifacts_uri(build_num))
        .select{|artifact| artifact['pretty_path'].match(/^\$CIRCLE_ARTIFACTS\/capybara_output\//)}
    screenshot_infos
      .map{|artifact| artifact['url'] + circle_token_query}
  end

  def get_latest_build_num
    recent_builds = get_recent_builds
    raise "No branch #{current_git_branch} found." unless recent_builds && recent_builds[0]
{'fraction_non_alphanumeric': 0.10485516115871073, 'fraction_numerical': 0.0016319869441044472, 'mean_word_length': 3.9336016096579476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2337408', 'n_tokens_mistral': 910, 'n_tokens_neox': 869, 'n_words': 149}