<commit_before>(ns open-company.util.export
  "
  Commandline client to export data from OpenCompany.

  Usage:

  lein run -m open-company.util.export -- buff ./opt/samples/buff.edn
  "
  (:require [clojure.string :as s]
            [clojure.tools.cli :refer (parse-opts)]
            [oc.lib.rethinkdb.pool :as db]
            [open-company.resources.common :as common]
            [open-company.resources.company :as company]
            [open-company.config :as c]
            [zprint.core :as zp])
  (:gen-class))

;; ----- CLI -----

(defn exit [status msg]
  (println msg)
  (System/exit status))

(def cli-options
  [["-h" "--help"]])

(defn error-msg [errors]
  (str "The following errors occurred while parsing your command:\n\n"
       (s/join \newline errors)))

(defn usage [options-summary]
  (s/join \newline
     ["\nThis program exports OpenCompany data to an EDN file."
      ""
      "Usage:"
      "  lein run -m open-company.util.export -- [organization slug] [edn file]"
      "  lein run -m open-company.util.export -- buff ./opt/samples/buff.edn"
      ""
      "Please refer to ./opt/samples for more information on the file format."
      ""]))

(defn -main [& args]
  (let [{:keys [options arguments errors summary]} (parse-opts args cli-options)]
    ;; Handle help and error conditions
    (cond
      (:help options) (exit 0 (usage summary))
      (not= (count arguments) 2) (exit 1 (usage summary))
      errors (exit 1 (error-msg errors)))
    ;; Export the organization, historic sections, and shared updates
    (try
      (let [conn (db/init-conn c/db-options)
            slug (first arguments)
            edn-file (second arguments)]
        (if-let [company (company/get-company conn slug)]
          (let [sections (common/read-resources conn common/section-table-name "company-slug" slug)
                updates (common/read-resources conn common/stakeholder-update-table-name "company-slug" slug)]
            (spit edn-file (zp/zprint-str
              {:company company
               :sections sections
               :updates updates}))
            (exit 0 (str "\nExport of " slug " to " edn-file " completed.\n")))
          (exit 1 (str "\nNot found: " slug "\n"))))
      (catch Exception e
        (println e)
        (exit 1 "Exception exporting.")))))<commit_msg>Fix RethinkDB cursor in export results.<commit_after>(ns open-company.util.export
  "
  Commandline client to export data from OpenCompany.

  Usage:

  lein run -m open-company.util.export -- buff ./opt/samples/buff.edn
  "
  (:require [clojure.string :as s]
            [clojure.tools.cli :refer (parse-opts)]
            [oc.lib.rethinkdb.pool :as db]
            [open-company.resources.common :as common]
            [open-company.resources.company :as company]
            [open-company.config :as c]
            [zprint.core :as zp])
  (:gen-class))

;; ----- CLI -----

(defn exit [status msg]
  (println msg)
  (System/exit status))

(def cli-options
  [["-h" "--help"]])

(defn error-msg [errors]
  (str "The following errors occurred while parsing your command:\n\n"
       (s/join \newline errors)))

(defn usage [options-summary]
  (s/join \newline
     ["\nThis program exports OpenCompany data to an EDN file."
      ""
      "Usage:"
      "  lein run -m open-company.util.export -- [organization slug] [edn file]"
      "  lein run -m open-company.util.export -- buff ./opt/samples/buff.edn"
      ""
      "Please refer to ./opt/samples for more information on the file format."
      ""]))

(defn -main [& args]
  (let [{:keys [options arguments errors summary]} (parse-opts args cli-options)]
    ;; Handle help and error conditions
    (cond
      (:help options) (exit 0 (usage summary))
      (not= (count arguments) 2) (exit 1 (usage summary))
      errors (exit 1 (error-msg errors)))
    ;; Export the organization, historic sections, and shared updates
    (try
      (let [conn (db/init-conn c/db-options)
            slug (first arguments)
            edn-file (second arguments)]
        (if-let [company (company/get-company conn slug)]
          (let [sections (common/read-resources conn common/section-table-name "company-slug" slug)
                updates (vec (sort-by :created-at (common/read-resources conn common/stakeholder-update-table-name "company-slug" slug)))]
            (spit edn-file (zp/zprint-str
              {:company company
               :sections sections
               :updates updates}))
            (exit 0 (str "\nExport of " slug " to " edn-file " completed.\n")))
          (exit 1 (str "\nNot found: " slug "\n"))))
      (catch Exception e
        (println e)
        (exit 1 "Exception exporting.")))))
{'fraction_non_alphanumeric': 0.13822525597269625, 'fraction_numerical': 0.0029863481228668944, 'mean_word_length': 2.283613445378151, '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': '3082192', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1421, 'n_words': 437}