<commit_before>require "heroku/client"
require 'tmpdir'

class Heroku::Client::PgbackupsArchive

  attr_reader :client, :backup

  def initialize(attrs={})
    Heroku::Command.load
    @client = Heroku::Client::Pgbackups.new attrs[:pgbackups_url]
    @backup = nil
    @environment = attrs[:env] || (defined?(Rails) ? Rails.env : nil)
  end

  def capture
    @backup = @client.create_transfer database_url, database_url, nil, "BACKUP", :expire => true

    until @backup["finished_at"]
      print "."
      sleep 1
      @backup = @client.get_transfer @backup["id"]
    end

    @backup
  end

  def database_url
    ENV["PGBACKUPS_DATABASE_URL"] || ENV["DATABASE_URL"]
  end


  def file 
    File.open(temp_file_path, 'wb') do |output|
      streamer = lambda do |chunk, remaining_bytes, total_bytes|
        puts "Download backup : #{(remaining_bytes.to_f / total_bytes) * 100}%"  
        output.write chunk
      end
      Excon.get(@backup["public_url"], :response_block => streamer)
    end
    File.open temp_file_path, 'r'
  end

  def temp_file_path
    "#{Dir.tmpdir}/#{URI(@backup["public_url"]).path.split('/').last}"
  end

  def key
    ["pgbackups", @environment, @backup["finished_at"].gsub(/\/|\:|\.|\s/, "-").concat(".dump")].join("/")
  end

  def store
    PgbackupsArchive::Storage.new(key, file).store
  end

end
<commit_msg>Syntax adjustments.<commit_after>require "heroku/client"
require "tmpdir"

class Heroku::Client::PgbackupsArchive

  attr_reader :client, :backup

  def initialize(attrs={})
    Heroku::Command.load
    @client      = Heroku::Client::Pgbackups.new attrs[:pgbackups_url]
    @backup      = nil
    @environment = attrs[:env] || (defined?(Rails) ? Rails.env : nil)
  end

  def capture
    @backup = @client.create_transfer(database_url, database_url, nil,
      "BACKUP", :expire => true)

    until @backup["finished_at"]
      print "."
      sleep 1
      @backup = @client.get_transfer @backup["id"]
    end

    @backup
  end

  def database_url
    ENV["PGBACKUPS_DATABASE_URL"] || ENV["DATABASE_URL"]
  end

  def file
    File.open(temp_file_path, "wb") do |output|
      streamer = lambda do |chunk, remaining_bytes, total_bytes|
        puts "Download backup : #{(remaining_bytes.to_f / total_bytes) * 100}%"
        output.write chunk
      end
      Excon.get(@backup["public_url"], :response_block => streamer)
    end
    File.open temp_file_path, "r"
  end

  def temp_file_path
    "#{Dir.tmpdir}/#{URI(@backup["public_url"]).path.split('/').last}"
  end

  def key
    ["<KEY>", @environment, @backup["finished_at"]
      .gsub(/\/|\:|\.|\s/, "-").concat(".dump")].join("/")
  end

  def store
    PgbackupsArchive::Storage.new(key, file).store
  end

end

{'fraction_non_alphanumeric': 0.15466568699485672, 'fraction_numerical': 0.0029390154298310064, 'mean_word_length': 3.329093799682035, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3015911', 'n_tokens_mistral': 968, 'n_tokens_neox': 936, 'n_words': 191}