Skip to content

Instantly share code, notes, and snippets.

@BenjaminWolfe
Last active March 1, 2020 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenjaminWolfe/5843f46a9713da9cb7b5e354236c3e61 to your computer and use it in GitHub Desktop.
Save BenjaminWolfe/5843f46a9713da9cb7b5e354236c3e61 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(slackteams)
library(slackr)
library(lubridate)
library(here)
library(glue)
library(conflicted)
library(fs)
conflict_prefer("filter", "dplyr", "stats" )
conflict_prefer("here" , "here" , "lubridate")
load_teams()
activate_team("exsurance")
# get current users. add time zone (tz_label) just for interest's sake.
# tried but failed with `mutate(current_time = map(tz, lubridate::now))`
# cool thing is at least the time zone names are the same as OlsonNames()
# title, status_text and status_emoji could be interesting, but are mostly empty
# image_512 could be cool but is often just a user silhouette
members <-
slackr_users() %>%
as_tibble() %>%
filter(name != "slackbot") %>%
select(real_name, tz_label)
# create folder and dummy file if necessary
if (!dir_exists(here("data/introductions"))) {
dir_create(here("data/introductions"))
}
if (!length(dir_ls(here("data/introductions")))) {
members %>%
filter(real_name == "Benjamin Wolfe") %>%
write_csv(path = here(glue("data/introductions/drawn-{today()}.csv")))
}
# get list of users already drawn at random (or just dummy file if first time)
already_drawn <-
dir_info(here("data/introductions")) %>%
filter(str_detect(path, "drawn")) %>%
mutate(users = map(path, read_csv)) %>%
unnest(users) %>%
select(path, modification_time, real_name, time_zone = tz_label)
# draw 2 users, and save drawing to a file
set.seed(42)
drawn_today <-
members %>%
anti_join(already_drawn, by = "real_name") %>%
sample_n(1) %>%
glimpse()
write_csv(
drawn_today,
path = here(glue("data/introductions/drawn-{today()}.csv"))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment