Skip to content

Commit 91b0131

Browse files
blueprint course associations
1 parent 2a0401e commit 91b0131

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

associate_blueprint.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Associate a blueprint course with courses in a subaccount. This does not
3+
sync materials, just adds courses to the blueprint.
4+
"""
5+
import csv
6+
from canvasapi import Canvas
7+
from config import TEST_KEY, TEST_URL, PROD_KEY, PROD_URL
8+
9+
canvas = Canvas(PROD_URL, PROD_KEY)
10+
blueprint_id = 47523
11+
course_ids = []
12+
13+
# Get the blueprint course
14+
blueprint_course = canvas.get_course(blueprint_id).get_blueprint()
15+
16+
# Read a CSV and loop each course ID
17+
with open('file.csv', 'r') as input:
18+
# Uncomment to skip a header row
19+
# next(input)
20+
for row in csv.reader(input):
21+
# Canvas-formatted CSVs have the course ID is column 1. Change this
22+
# reference if you're using a different format.
23+
course_ids.append(row[0])
24+
25+
# Make a batch association
26+
blueprint_course.update_associated_courses(course_ids_to_add=course_ids)
27+
28+
updated_list = blueprint_course.get_associated_courses()
29+
print(f'{len(list(updated_list))} now associated')
30+

0 commit comments

Comments
 (0)