~drewr/sheets

6acbed5f784683b25f6cda236723a56fe209ba5e — Drew Raines 3 years ago 2dcc363
WIP, get data from an actual sheet
2 files changed, 47 insertions(+), 6 deletions(-)

M project.clj
M src/sheets/core.clj
M project.clj => project.clj +2 -1
@@ 3,5 3,6 @@
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.10.1"]]
  :dependencies [[org.clojure/clojure "1.10.1"]
                 [google-apps-clj "0.6.1"]]
  :repl-options {:init-ns sheets.core})

M src/sheets/core.clj => src/sheets/core.clj +45 -5
@@ 1,6 1,46 @@
(ns sheets.core)
(ns sheets.core
  (:require [clojure.edn :as edn]
            [clojure.spec.alpha :as s]
            [google-apps-clj.credentials :as auth]
            [google-apps-clj.google-sheets-v4 :as sheets])
  (:import (com.google.api.services.sheets.v4 SheetsScopes)))

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))
(def spreadsheet-id
  "1WdMTOhw4nYAF_zpEqyCZCW26nzdtZXZhdBt1sEJN_kY")

(def spreadsheet-sheet-name
  "Form Responses 1")

(def field-map
  {::business-name              "Business Name"
   ::contact-first              "First Name"
   ::contact-last               "Last Name"
   ::business-description       "Business Description (Describe your service) "
   ::website                    "Website"
   ::phone                      "Preferred Phone Number "
   ::call-for-updated-info?     "called for updated info? "
   ::updated-info?              "updated info recieved? "
   ::email                      "Preferred Email Address"
   ::instagram                  "Instagram (@name)"
   ::facebook                   "Facebook url"
   ::twitter                    "Twitter (@name)"
   ::business-mailing-address   "Mailing Address (Street address, City, State, Zip Code)"
   ::industry                   "What industry best describes your business"
   })

(s/def ::config
  (s/keys :req (keys field-map)))

(defn sheet-rows [svc spreadsheet-id sheet-name]
  (sheets/get-cell-values svc spreadsheet-id [(str sheet-name "!A1:Z1000")]))

(defn non-blank-lines [line]
  (not= {} (dissoc (frequencies line) nil)))

(defn main [spreadsheet-id sheet-name]
  (let [scopes [SheetsScopes/SPREADSHEETS_READONLY]
        creds (auth/default-credential scopes)
        svc (sheets/build-service creds)]
    (->> (sheet-rows svc spreadsheet-id sheet-name)
         first
         (filter non-blank-lines))))