Skip to content

Instantly share code, notes, and snippets.

@jonovik
Last active February 23, 2021 10:21
Show Gist options
  • Save jonovik/f2e938eccd0734a77c513e42ce0f3850 to your computer and use it in GitHub Desktop.
Save jonovik/f2e938eccd0734a77c513e42ce0f3850 to your computer and use it in GitHub Desktop.
Export Canvas groups to a Zoom breakout participant list.
# PREPARATIONS:
#
# * Have Teacher status in your Canvas course.
# * Get an API token for your Canvas account as described here:
# https://community.canvaslms.com/t5/Admin-Guide/How-do-I-manage-API-access-tokens-as-an-admin/ta-p/89
# You only need to do this once. If you generate a new token, the old one becomes invalid.
# Keep your API token secret. It works like a password.
# * Find your course's ID number in Canvas. For example, course 1234 is at
# https://nmbu.instructure.com/courses/1234
# * Install revision 7496d66 of rcanvas
# (I experience bugs in authentication in later revisions as of 2021-02-23)
# remotes::install_github(repo = "daranzolin/rcanvas", ref = "7496d66")
library(rcanvas)
library(tidyverse)
# ADJUSTMENTS FOR YOUR COURSE:
course_id <- 1234 # Replace with your course id
Sys.setenv(CANVAS_DOMAIN="https://nmbu.instructure.com") # Change if you're not at NMBU
# Insert your API token below. Keep it private; it works as a password!
Sys.setenv(CANVAS_API_TOKEN="10453~1k...")
# User Groups:
ug <- get_course_user_groups(course_id) %>%
as_tibble %>%
filter(sortable_name != "Student, Test")
# Users:
u <- do_query(c("courses", course_id, "users"),
args = list(enrollment_type = "student")) %>%
as_tibble
# Add columns from u to ug into data frame:
d <- ug %>% full_join(u %>% select(id, name, login_id, email), by = "id")
# Export to Zoom:
d %>%
select(group_name, email) %>%
write_csv(paste0(course_id, "_zoom.csv"))
# EXCEL WILL MESS UP INTERNATIONAL CHARACTERS (ÆØÅ etc)
# if you open a CSV file directly.
# Instead, create an empty Excel workbook and choose
# Data > From Text/CSV (button near upper left) > Choose your file >
# Choose File origin: "65001 Unicode (UTF-8)"
# (it's listed alphabetically under U)
# and click Load.
# OTHER STUFF YOU MIGHT WANT TO DO:
# Canvas Gradebook sorts in the order determined by the display language.
# If we want to match e.g. Norwegian, we can:
# stringi::stri_sort(u$sortable_name, locale = "nb_NO")
# Students not in a group:
# d %>% filter(is.na(group_name))
# Students in multiple groups:
# d %>% count(sortable_name, sort = TRUE, name = "grupper") %>% filter(grupper > 1)
# You can extract pieces of information from group names
# using regular expressions, see https://regex101.com
# Here's an example from STAT100, which has e.g.
# "Fysisk kollokvie 1", "Digital kollokvie 5", "Individuelt løp 23"
#
# extract(ug,
# group_name,
# into = c("gruppe", "nummer"),
# # https://regex101.com/r/Zi0n52/1
# regex = "(.*?) ([0-9]+)",
# remove = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment