Last active
March 1, 2020 16:58
-
-
Save BenjaminWolfe/5843f46a9713da9cb7b5e354236c3e61 to your computer and use it in GitHub Desktop.
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
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