<commit_before>require "fileutils"
require "ostruct"

class WhitehallEuExitReport
  def self.call(*args)
    new(*args).call
  end

  def initialize(path:)
    @path = path
  end

  def call
    organisations.find_each do |organisation|
      puts organisation.title, organisation.content_id

      slug = organisation.base_path[26..-1] # /government/organisations/
      org_path = File.join(path, slug)
      FileUtils::mkdir_p(org_path)

      export_content_csv(organisation, File.join(org_path, "content_with_descendants.csv"), include_descendants: true)
      export_content_csv(organisation, File.join(org_path, "content.csv"))
    end
  end

  private_class_method :new

private

  CSV_HEADERS = ["Title", "URL", "Last updated", "Document type", "Taxon", "EU Exit related?"].freeze

  EU_EXIT_TAXONS = [
    "21eee04d-e702-4e7b-9fde-2f6777f1be2c", # business / business and enterprise
    "ed2ca1f7-5463-4eda-9324-b597e269e242", # business / trade and investment
    "4ef6d013-ec2d-4ae8-a1a0-5a984e6e6c42", # business / media and communications
    "da0bc015-f8e5-492c-8d81-6fbf9b18947c", # business / consumer rights and issues
    "35f5b496-add7-4263-8084-8510461881fe", # business / employing people
    "ccb77bcc-56b4-419a-b5ce-f7c2234e0546", # business / science and innovation
    "a1e4659c-dc15-48be-bc4f-6c609ae061dc", # business / uk economy
    "cb4c8377-6fcb-4022-a7a1-98395eb50508", # business / water industry

    "dd767840-363e-43ad-8835-c9ab516633de", # education / funding and higher education skills and vocational training
    "ff00b8b2-dcdb-4659-93c2-291c9be354f3", # education / teaching and leadership
    "23265b25-7ec3-4960-8517-4ff8d4d92cac", # education / funding and finance for students

    "6e85c12f-f52b-41b3-93ad-59e5f19d64f6", # entering and staying in the uk / rights of foreign nationals in the uk<commit_msg>Don't create folders for organisations with no content<commit_after>require "fileutils"
require "ostruct"

class WhitehallEuExitReport
  def self.call(*args)
    new(*args).call
  end

  def initialize(path:)
    @path = path
  end

  def call
    organisations.find_each do |organisation|
      puts organisation.title, organisation.content_id

      next unless content_by(organisation).exists?

      slug = organisation.base_path[26..-1] # /government/organisations/
      org_path = File.join(path, slug)
      FileUtils::mkdir_p(org_path)

      export_content_csv(organisation, File.join(org_path, "content_with_descendants.csv"), include_descendants: true)
      export_content_csv(organisation, File.join(org_path, "content.csv"))
    end
  end

  private_class_method :new

private

  CSV_HEADERS = ["Title", "URL", "Last updated", "Document type", "Taxon", "EU Exit related?"].freeze

  EU_EXIT_TAXONS = [
    "21eee04d-e702-4e7b-9fde-2f6777f1be2c", # business / business and enterprise
    "ed2ca1f7-5463-4eda-9324-b597e269e242", # business / trade and investment
    "4ef6d013-ec2d-4ae8-a1a0-5a984e6e6c42", # business / media and communications
    "da0bc015-f8e5-492c-8d81-6fbf9b18947c", # business / consumer rights and issues
    "35f5b496-add7-4263-8084-8510461881fe", # business / employing people
    "ccb77bcc-56b4-419a-b5ce-f7c2234e0546", # business / science and innovation
    "a1e4659c-dc15-48be-bc4f-6c609ae061dc", # business / uk economy
    "cb4c8377-6fcb-4022-a7a1-98395eb50508", # business / water industry

    "dd767840-363e-43ad-8835-c9ab516633de", # education / funding and higher education skills and vocational training
    "ff00b8b2-dcdb-4659-93c2-291c9be354f3", # education / teaching and leadership
    "23265b25-7ec3-4960-8517-4ff8d4d92cac", # education / funding and finance for students

    "6e85c12f-f52b-41b3-93ad-59e5f19d64f6", # entering and staying in the uk / rights of foreign nationals in the uk
{'fraction_non_alphanumeric': 0.1071898867526995, 'fraction_numerical': 0.1279957861469581, 'mean_word_length': 4.057256990679095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4715856', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1405, 'n_words': 267}