Skip to content

Instantly share code, notes, and snippets.

Created April 18, 2023 17:16
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Get # of unique slack channel participants per month
{:deps {clj-http/clj-http {:mvn/version "3.12.3"}
org.jsoup/jsoup {:mvn/version "1.11.3"}}}
(ns co.tfos.slackstats
(:require [clj-http.client :as http]))
(def base-url "")
(defn format-inst [inst pattern]
(-> (java.time.format.DateTimeFormatter/ofPattern pattern)
(.withZone (java.time.ZoneId/systemDefault))
(.format inst)))
(defn get-stats [day]
(let [date-str (format-inst day "yyyy-MM-dd")
url (str base-url date-str)
doc (-> (http/get url
{:throw-exceptions false})
user-ids (->> (.select doc ".message_username")
(map (fn [node]
(subs (.attr node "href")
(count "/_/_/users/"))))
{:date date-str
:user-ids user-ids}))
(defn prev-day [inst]
(.plusSeconds inst (* -60 60 24)))
(def data (->> (iterate prev-day (java.time.Instant/now))
(take (* 18 30))
(mapv get-stats)
(spit "raw-data.edn" (pr-str data))
(->> data
(map #(update % :date subs 0 7))
(partition-by :date)
(run! (fn [data]
(println (str (:date (first data))
(count (set (mapcat :user-ids data))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment