Skip to content

Instantly share code, notes, and snippets.

@jimhester
Last active May 20, 2018 13:23
Show Gist options
  • Save jimhester/6bf009154c245910693ac80c70c91e39 to your computer and use it in GitHub Desktop.
Save jimhester/6bf009154c245910693ac80c70c91e39 to your computer and use it in GitHub Desktop.
Create flash cards of rOpenSci unconf participants. You can get the shared deck from https://ankiweb.net/shared/info/806702790 or by importing the 'unconf 2018.apkg' file in this gist
# On macOS Anki media files are stored in ~/Library/Application Support/Anki2/Username/collection.media/
# https://apps.ankiweb.net/docs/manual.html#file-locations
# get images from Unconf repo, resize them and write them to the new path
# Code assumes it is being run on macOS from the checkout of the conference repo, e.g. `git clone https://github.com/ropensci/unconf18 && cd unconf18`
library(fs)
library(magick)
imgs <- dir_ls("images/participants")
for (f in imgs) {
f %>%
image_read() %>%
image_resize("300x300") %>%
image_write(path("~/Library/Application Support/Anki2/User 1/collection.media/", path_file(f)))
}
library(tidyverse)
img_tbl <-
tibble(
img = path_file(imgs),
# Kevin's photo has an underscore instead of a -
short_name = fs::path_file(imgs) %>% fs::path_ext_remove() %>% sub("_", "-", .)
)
library(rvest)
participants <- read_html("index.html") %>% html_nodes(".participant")
participants_tbl <-
tibble(
short_name = participants %>% html_attr("class") %>% sub("participant ", "", .),
full_name = participants %>% html_node(".participant-name") %>% html_text() %>% sub("\t", " ", .),
affiliation = participants %>% html_node(".participant-affiliation") %>% html_text()
) %>%
left_join(img_tbl)
library(glue)
participants_tbl %>%
glue_data('"<img src=""{img}"" />"\t"{full_name}<br>{affiliation}"') %>%
write_lines("unconf.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment