Skip to content

Instantly share code, notes, and snippets.

@jacobobryant
Created April 18, 2023 17:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobobryant/55cfb2ae5975c5065938e2f049921f66 to your computer and use it in GitHub Desktop.
Save jacobobryant/55cfb2ae5975c5065938e2f049921f66 to your computer and use it in GitHub Desktop.
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 "https://clojurians-log.clojureverse.org/biff/")
(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})
:body
org.jsoup.Jsoup/parse)
user-ids (->> (.select doc ".message_username")
(map (fn [node]
(subs (.attr node "href")
(count "/_/_/users/"))))
set)]
{:date date-str
:user-ids user-ids}))
(defn prev-day [inst]
(.plusSeconds inst (* -60 60 24)))
(comment
(def data (->> (iterate prev-day (java.time.Instant/now))
(take (* 18 30))
(mapv get-stats)
time))
(spit "raw-data.edn" (pr-str data))
(->> data
(map #(update % :date subs 0 7))
(partition-by :date)
reverse
(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