<commit_before>require "confluencer"

module Enki
  module Confluence
    extend self

    def upload(options = {})
      file = options.delete(:file)
      title = options.delete(:title) || File.basename(file, '.*')
      space = options.delete(:space) || Enki.configuration.confluence_space

      content = File.read(file)

      confluence_session do
        page = Confluence::Page.new({
          space: space,
          title: title,
          content: content
        })

        Enki.logger.log "Uploading page #{title.inspect}..."
        page.store
        Enki.logger.log "Done!"
      end
    end
  end

  private
  def confluence_session
    options = {
      url: Enki.configuration.confluence_url,
      username: Enki.configuration.confluence_user,
      password: <PASSWORD>
    }

    Confluence::Session.new(options) do |client|
      yield(client)
    end
  end
end<commit_msg>use one session per upload<commit_after>require "confluencer"

module Enki
  module Confluence
    extend self

    def upload(options = {})
      file = options.delete(:file)
      title = options.delete(:title) || File.basename(file, '.*')
      space = options.delete(:space) || Enki.configuration.confluence_space

      content = File.read(file)

      page = Confluence::Page.new({
        space: space,
        title: title,
        content: content
      })

      Enki.logger.log "Uploading page #{title.inspect}..."
      page.store
      Enki.logger.log "Done!"
    end
  end

  def process_dir(dir)
    confluence_session do
      Dir.glob("#{dir}/**/*html").each do |file|
        upload(file: file)
      end
    end
  end

  private
  def confluence_session
    options = {
      url: Enki.configuration.confluence_url,
      username: Enki.configuration.confluence_user,
      password: <PASSWORD>
    }

    Confluence::Session.new(options) do |client|
      yield(client)
    end
  end
end
{'fraction_non_alphanumeric': 0.11181102362204724, 'fraction_numerical': 0.0, 'mean_word_length': 2.409660107334526, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3477204', 'n_tokens_mistral': 599, 'n_tokens_neox': 569, 'n_words': 126}