<commit_before>module Webshots
  class Processor

    # returns a path to a tmpfile containing a png with a screenshot
    def self.url_to_png(url, options_param={})
      raise "no url given" unless url

      default_options = {'crop-h' => 768, 'crop-w' => 1024, 'height' => 768, 'width' => 1024}
      options = default_options.merge(options_param)

      options_str = str_from_options(options)

       # Need to create a temporary file with a png extension that wkhtmltoimage can write to
      @tmp_file_path = File.dirname(Tempfile.new('screenshot')) + rand_str + '.png'
      
      cmd = "#{Webshots.executable} #{options_str} #{url} #{@tmp_file_path}"
      system(cmd)

      @tmp_file_path
    end

    private

    def self.rand_str(len=20)
      rand(36**len).to_s(36)<commit_msg>didnt use File.join between folder and file name causing heroku paths to crash<commit_after>module Webshots
  class Processor

    # returns a path to a tmpfile containing a png with a screenshot
    def self.url_to_png(url, options_param={})
      raise "no url given" unless url

      default_options = {'crop-h' => 768, 'crop-w' => 1024, 'height' => 768, 'width' => 1024}
      options = default_options.merge(options_param)

      options_str = str_from_options(options)

       # Need to create a temporary file with a png extension that wkhtmltoimage can write to
      @tmp_file_path = File.join(File.dirname(Tempfile.new('screenshot')), rand_str) + '.png'
      
      cmd = "#{Webshots.executable} #{options_str} #{url} #{@tmp_file_path}"
      system(cmd)

      @tmp_file_path
    end

    private

    def self.rand_str(len=20)
      rand(36**len).to_s(36)
{'fraction_non_alphanumeric': 0.11184606133493687, 'fraction_numerical': 0.024052916416115455, 'mean_word_length': 3.2666666666666666, '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': '4300669', 'n_tokens_mistral': 582, 'n_tokens_neox': 524, 'n_words': 149}