Created
April 18, 2023 17:16
-
-
Save jacobobryant/55cfb2ae5975c5065938e2f049921f66 to your computer and use it in GitHub Desktop.
Get # of unique slack channel participants per month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:deps {clj-http/clj-http {:mvn/version "3.12.3"} | |
org.jsoup/jsoup {:mvn/version "1.11.3"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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