{"action":"created","comment":{"url":"https://api.github.com/repos/democracyworks/user-works/pulls/comments/72629633","id":72629633,"diff_hunk":"@@ -1,157 +1,49 @@\n (ns user-works.export\n   (:require\n-    [clj-time.coerce :as tc]\n-    [clj-time.core :as t]\n-    [clj-time.format :as tf]\n-    [clojure.java.io :as io]\n-    [clojure.data.csv :as csv]\n-    [datomic.api :as d]))\n-\n-(defn find-users-with-email\n-  [db email]\n-  (->> (d/q '{:find [[?user ...]]\n-              :in [$ ?email]\n-              :where [[?user :user/email ?email]]}\n-            db email)\n-       (mapv #(d/entity db %))))\n-\n-(defn format-date-of-birth\n-  [dt]\n-  (if dt\n-    (tf/unparse (tf/formatter :date) (tc/from-date dt))\n-    dt))\n-\n-(defn format-user-record\n-  \"Transducer which\n-    - extracts the entity into a map\n-    - formats the user record to flatten the address\n-    - formats the DOB properly into YYYY-MM-DD format.\"\n-  [db]\n-  (comp\n-   (map #(->> % (d/entity db) (into {})))\n-   (map #(merge % (into {} (:user/address %))))\n-   (map #(dissoc % :user/address))\n-   (map #(update % :user/dob format-date-of-birth))))\n-\n-(defn find-users-with-hostname\n-  [db hostname]\n-  (->> (d/q '{:find [[?user ...]]\n-              :in [$ ?hostname]\n-              :where [[?user :user/hostname ?hostname]]}\n-            db hostname)\n-       (into [] (format-user-record db))))\n-\n-(defn all-users'\n-  [db]\n-  (d/q '{:find [[?user ...]]\n-         :in [$]\n-         :where [[?user :user/id]]}\n-       db))\n-\n-(defn all-users\n-  [db]\n-  (->> (all-users' db)\n-       (into [] (format-user-record db))))\n-\n-;; Expects to be connecting to the user-works partition\n-;; via the production datomic URI\n-\n-(defn get-db\n+    [clojure.string :as str]\n+    [datomic.api :as d]\n+    [user-works.entities.user :as users]\n+    [user-works.handlers.export :as export-handler]))\n+\n+(defn connect-to-user-works-db\n+  \"Expects to be connecting to the user-works partition\n+  via the production datomic URI, assumes the environment\n+  variable 'USER_WORKS_DATOMIC_URI' is set with this value.\"\n   []\n-  (->> (d/connect (System/getenv \"DATOMIC_URI\"))\n-       d/db))\n-\n-(def ordered-keys\n-  [:user/id\n-   :user/first-name\n-   :user/middle-name\n-   :user/last-name\n-   :user/phone\n-   :user/email\n-   :address/street\n-   :address/street-2\n-   :address/city\n-   :address/state\n-   :address/zip\n-   :user/dob\n-   :user/language-preference\n-   :user/hostname])\n-\n-(defn export-all-users!\n-  [filename]\n-  (let [formatted-users (->> (all-users (get-db))\n-                             (sort-by :user/first-name)\n-                             (map (apply juxt ordered-keys)))]\n-    (with-open [out-file (io/writer filename)]\n-      (csv/write-csv out-file [(map name ordered-keys)])\n-      (csv/write-csv out-file formatted-users))))\n-\n-(defn gen-filename\n-  []\n-  (let [date-str (tf/unparse (tf/formatter :date) (t/now))]\n-    (str \"users-\" date-str \".csv\")))\n+  (d/connect (System/getenv \"USER_WORKS_DATOMIC_URI\")))\n+\n+(defn export-users!\n+  [conn hostnames filename]\n+  (let [db (d/db conn)\n+        users (case hostnames\n+                \":all\" (users/all-users db)\n+                (users/find-by-hostnames db (str/split hostnames #\"\\s\")))]\n+     (-> (into [] (export-handler/format-user-record) users)\n+         (export-handler/generate-csv! filename))\n+    (println \"Exported users for \" hostnames \" in file \" filename)))","path":"dev-src/user_works/export.clj","position":112,"original_position":112,"commit_id":"4518dbe876b1e992aad0cc782d7e9dc36e6d8daa","original_commit_id":"4518dbe876b1e992aad0cc782d7e9dc36e6d8daa","user":{"login":"tank157","id":4147,"avatar_url":"https://avatars.githubusercontent.com/u/4147?v=3","gravatar_id":"","url":"https://api.github.com/users/tank157","html_url":"https://github.com/tank157","followers_url":"https://api.github.com/users/tank157/followers","following_url":"https://api.github.com/users/tank157/following{/other_user}","gists_url":"https://api.github.com/users/tank157/gists{/gist_id}","starred_url":"https://api.github.com/users/tank157/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tank157/subscriptions","organizations_url":"https://api.github.com/users/tank157/orgs","repos_url":"https://api.github.com/users/tank157/repos","events_url":"https://api.github.com/users/tank157/events{/privacy}","received_events_url":"https://api.github.com/users/tank157/received_events","type":"User","site_admin":false},"body":"Can this be changed into log/debug please?","created_at":"2016-07-28T14:14:35Z","updated_at":"2016-07-28T14:14:35Z","html_url":"https://github.com/democracyworks/user-works/pull/28#discussion_r72629633","pull_request_url":"https://api.github.com/repos/democracyworks/user-works/pulls/28","_links":{"self":{"href":"https://api.github.com/repos/democracyworks/user-works/pulls/comments/72629633"},"html":{"href":"https://github.com/democracyworks/user-works/pull/28#discussion_r72629633"},"pull_request":{"href":"https://api.github.com/repos/democracyworks/user-works/pulls/28"}}},"pull_request":{"url":"https://api.github.com/repos/democracyworks/user-works/pulls/28","id":78540015,"html_url":"https://github.com/democracyworks/user-works/pull/28","diff_url":"https://github.com/democracyworks/user-works/pull/28.diff","patch_url":"https://github.com/democracyworks/user-works/pull/28.patch","issue_url":"https://api.github.com/repos/democracyworks/user-works/issues/28","number":28,"state":"open","locked":false,"title":"User Export for Turbovote Admin Dashboard, v1","user":{"login":"ddellacosta","id":32021,"avatar_url":"https://avatars.githubusercontent.com/u/32021?v=3","gravatar_id":"","url":"https://api.github.com/users/ddellacosta","html_url":"https://github.com/ddellacosta","followers_url":"https://api.github.com/users/ddellacosta/followers","following_url":"https://api.github.com/users/ddellacosta/following{/other_user}","gists_url":"https://api.github.com/users/ddellacosta/gists{/gist_id}","starred_url":"https://api.github.com/users/ddellacosta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ddellacosta/subscriptions","organizations_url":"https://api.github.com/users/ddellacosta/orgs","repos_url":"https://api.github.com/users/ddellacosta/repos","events_url":"https://api.github.com/users/ddellacosta/events{/privacy}","received_events_url":"https://api.github.com/users/ddellacosta/received_events","type":"User","site_admin":false},"body":"https://www.pivotaltracker.com/story/show/119558509","created_at":"2016-07-22T21:03:46Z","updated_at":"2016-07-28T14:14:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5ec7dba3d350c717957da153f6d4652e5989bfa6","assignee":{"login":"tank157","id":4147,"avatar_url":"https://avatars.githubusercontent.com/u/4147?v=3","gravatar_id":"","url":"https://api.github.com/users/tank157","html_url":"https://github.com/tank157","followers_url":"https://api.github.com/users/tank157/followers","following_url":"https://api.github.com/users/tank157/following{/other_user}","gists_url":"https://api.github.com/users/tank157/gists{/gist_id}","starred_url":"https://api.github.com/users/tank157/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tank157/subscriptions","organizations_url":"https://api.github.com/users/tank157/orgs","repos_url":"https://api.github.com/users/tank157/repos","events_url":"https://api.github.com/users/tank157/events{/privacy}","received_events_url":"https://api.github.com/users/tank157/received_events","type":"User","site_admin":false},"assignees":[{"login":"tank157","id":4147,"avatar_url":"https://avatars.githubusercontent.com/u/4147?v=3","gravatar_id":"","url":"https://api.github.com/users/tank157","html_url":"https://github.com/tank157","followers_url":"https://api.github.com/users/tank157/followers","following_url":"https://api.github.com/users/tank157/following{/other_user}","gists_url":"https://api.github.com/users/tank157/gists{/gist_id}","starred_url":"https://api.github.com/users/tank157/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tank157/subscriptions","organizations_url":"https://api.github.com/users/tank157/orgs","repos_url":"https://api.github.com/users/tank157/repos","events_url":"https://api.github.com/users/tank157/events{/privacy}","received_events_url":"https://api.github.com/users/tank157/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/democracyworks/user-works/pulls/28/commits","review_comments_url":"https://api.github.com/repos/democracyworks/user-works/pulls/28/comments","review_comment_url":"https://api.github.com/repos/democracyworks/user-works/pulls/comments{/number}","comments_url":"https://api.github.com/repos/democracyworks/user-works/issues/28/comments","statuses_url":"https://api.github.com/repos/democracyworks/user-works/statuses/4518dbe876b1e992aad0cc782d7e9dc36e6d8daa","head":{"label":"democracyworks:user-export-v1","ref":"user-export-v1","sha":"4518dbe876b1e992aad0cc782d7e9dc36e6d8daa","user":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"repo":{"id":35972977,"name":"user-works","full_name":"democracyworks/user-works","owner":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/democracyworks/user-works","description":"Store user information.","fork":false,"url":"https://api.github.com/repos/democracyworks/user-works","forks_url":"https://api.github.com/repos/democracyworks/user-works/forks","keys_url":"https://api.github.com/repos/democracyworks/user-works/keys{/key_id}","collaborators_url":"https://api.github.com/repos/democracyworks/user-works/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/democracyworks/user-works/teams","hooks_url":"https://api.github.com/repos/democracyworks/user-works/hooks","issue_events_url":"https://api.github.com/repos/democracyworks/user-works/issues/events{/number}","events_url":"https://api.github.com/repos/democracyworks/user-works/events","assignees_url":"https://api.github.com/repos/democracyworks/user-works/assignees{/user}","branches_url":"https://api.github.com/repos/democracyworks/user-works/branches{/branch}","tags_url":"https://api.github.com/repos/democracyworks/user-works/tags","blobs_url":"https://api.github.com/repos/democracyworks/user-works/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/democracyworks/user-works/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/democracyworks/user-works/git/refs{/sha}","trees_url":"https://api.github.com/repos/democracyworks/user-works/git/trees{/sha}","statuses_url":"https://api.github.com/repos/democracyworks/user-works/statuses/{sha}","languages_url":"https://api.github.com/repos/democracyworks/user-works/languages","stargazers_url":"https://api.github.com/repos/democracyworks/user-works/stargazers","contributors_url":"https://api.github.com/repos/democracyworks/user-works/contributors","subscribers_url":"https://api.github.com/repos/democracyworks/user-works/subscribers","subscription_url":"https://api.github.com/repos/democracyworks/user-works/subscription","commits_url":"https://api.github.com/repos/democracyworks/user-works/commits{/sha}","git_commits_url":"https://api.github.com/repos/democracyworks/user-works/git/commits{/sha}","comments_url":"https://api.github.com/repos/democracyworks/user-works/comments{/number}","issue_comment_url":"https://api.github.com/repos/democracyworks/user-works/issues/comments{/number}","contents_url":"https://api.github.com/repos/democracyworks/user-works/contents/{+path}","compare_url":"https://api.github.com/repos/democracyworks/user-works/compare/{base}...{head}","merges_url":"https://api.github.com/repos/democracyworks/user-works/merges","archive_url":"https://api.github.com/repos/democracyworks/user-works/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/democracyworks/user-works/downloads","issues_url":"https://api.github.com/repos/democracyworks/user-works/issues{/number}","pulls_url":"https://api.github.com/repos/democracyworks/user-works/pulls{/number}","milestones_url":"https://api.github.com/repos/democracyworks/user-works/milestones{/number}","notifications_url":"https://api.github.com/repos/democracyworks/user-works/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/democracyworks/user-works/labels{/name}","releases_url":"https://api.github.com/repos/democracyworks/user-works/releases{/id}","deployments_url":"https://api.github.com/repos/democracyworks/user-works/deployments","created_at":"2015-05-20T20:39:38Z","updated_at":"2016-01-22T19:53:13Z","pushed_at":"2016-07-27T19:28:02Z","git_url":"git://github.com/democracyworks/user-works.git","ssh_url":"git@github.com:democracyworks/user-works.git","clone_url":"https://github.com/democracyworks/user-works.git","svn_url":"https://github.com/democracyworks/user-works","homepage":null,"size":179,"stargazers_count":0,"watchers_count":0,"language":"Clojure","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"democracyworks:master","ref":"master","sha":"aaf1a08aa031ee4787586c73e03cb84e27662300","user":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"repo":{"id":35972977,"name":"user-works","full_name":"democracyworks/user-works","owner":{"login":"democracyworks","id":1373557,"avatar_url":"https://avatars.githubusercontent.com/u/1373557?v=3","gravatar_id":"","url":"https://api.github.com/users/democracyworks","html_url":"https://github.com/democracyworks","followers_url":"https://api.github.com/users/democracyworks/followers","following_url":"https://api.github.com/users/democracyworks/following{/other_user}","gists_url":"https://api.github.com/users/democracyworks/gists{/gist_id}","starred_url":"https://api.github.com/users/democracyworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/democracyworks/subscriptions","organizations_url":"https://api.github.com/users/democracyworks/orgs","repos_url":"https://api.github.com/users/democracyworks/repos","events_url":"https://api.github.com/users/democracyworks/events{/privacy}","received_events_url":"https://api.github.com/users/democracyworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/democracyworks/user-works","description":"Store user information.","fork":false,"url":"https://api.github.com/repos/democracyworks/user-works","forks_url":"https://api.github.com/repos/democracyworks/user-works/forks","keys_url":"https://api.github.com/repos/democracyworks/user-works/keys{/key_id}","collaborators_url":"https://api.github.com/repos/democracyworks/user-works/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/democracyworks/user-works/teams","hooks_url":"https://api.github.com/repos/democracyworks/user-works/hooks","issue_events_url":"https://api.github.com/repos/democracyworks/user-works/issues/events{/number}","events_url":"https://api.github.com/repos/democracyworks/user-works/events","assignees_url":"https://api.github.com/repos/democracyworks/user-works/assignees{/user}","branches_url":"https://api.github.com/repos/democracyworks/user-works/branches{/branch}","tags_url":"https://api.github.com/repos/democracyworks/user-works/tags","blobs_url":"https://api.github.com/repos/democracyworks/user-works/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/democracyworks/user-works/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/democracyworks/user-works/git/refs{/sha}","trees_url":"https://api.github.com/repos/democracyworks/user-works/git/trees{/sha}","statuses_url":"https://api.github.com/repos/democracyworks/user-works/statuses/{sha}","languages_url":"https://api.github.com/repos/democracyworks/user-works/languages","stargazers_url":"https://api.github.com/repos/democracyworks/user-works/stargazers","contributors_url":"https://api.github.com/repos/democracyworks/user-works/contributors","subscribers_url":"https://api.github.com/repos/democracyworks/user-works/subscribers","subscription_url":"https://api.github.com/repos/democracyworks/user-works/subscription","commits_url":"https://api.github.com/repos/democracyworks/user-works/commits{/sha}","git_commits_url":"https://api.github.com/repos/democracyworks/user-works/git/commits{/sha}","comments_url":"https://api.github.com/repos/democracyworks/user-works/comments{/number}","issue_comment_url":"https://api.github.com/repos/democracyworks/user-works/issues/comments{/number}","contents_url":"https://api.github.com/repos/democracyworks/user-works/contents/{+path}","compare_url":"https://api.github.com/repos/democracyworks/user-works/compare/{base}...{head}","merges_url":"https://api.github.com/repos/democracyworks/user-works/merges","archive_url":"https://api.github.com/repos/democracyworks/user-works/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/democracyworks/user-works/downloads","issues_url":"https://api.github.com/repos/democracyworks/user-works/issues{/number}","pulls_url":"https://api.github.com/repos/democracyworks/user-works/pulls{/number}","milestones_url":"https://api.github.com/repos/democracyworks/user-works/milestones{/number}","notifications_url":"https://api.github.com/repos/democracyworks/user-works/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/democracyworks/user-works/labels{/name}","releases_url":"https://api.github.com/repos/democracyworks/user-works/releases{/id}","deployments_url":"https://api.github.com/repos/democracyworks/user-works/deployments","created_at":"2015-05-20T20:39:38Z","updated_at":"2016-01-22T19:53:13Z","pushed_at":"2016-07-27T19:28:02Z","git_url":"git://github.com/democracyworks/user-works.git","ssh_url":"git@github.com:democracyworks/user-works.git","clone_url":"https://github.com/democracyworks/user-works.git","svn_url":"https://github.com/democracyworks/user-works","homepage":null,"size":179,"stargazers_count":0,"watchers_count":0,"language":"Clojure","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/democracyworks/user-works/pulls/28"},"html":{"href":"https://github.com/democracyworks/user-works/pull/28"},"issue":{"href":"https://api.github.com/repos/democracyworks/user-works/issues/28"},"comments":{"href":"https://api.github.com/repos/democracyworks/user-works/issues/28/comments"},"review_comments":{"href":"https://api.github.com/repos/democracyworks/user-works/pulls/28/comments"},"review_comment":{"href":"https://api.github.com/repos/democracyworks/user-works/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/democracyworks/user-works/pulls/28/commits"},"statuses":{"href":"https://api.github.com/repos/democracyworks/user-works/statuses/4518dbe876b1e992aad0cc782d7e9dc36e6d8daa"}}}}
{"actor":{"display_login":"tank157"}}