Repository navigation
Expand file tree
/
Copy pathCanvas_Enroll_Teacher_In_Course.py
More file actions
54 lines (52 loc) · 1.69 KB
/
Copy pathCanvas_Enroll_Teacher_In_Course.py
File metadata and controls
54 lines (52 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pandas as pd
import requests, json, logging, smtplib, datetime, sys
from canvasapi import Canvas
from canvasapi.exceptions import CanvasException
from pathlib import Path
#
# Quick and easy way to enroll a teacher as teacher in a class.
# python Canvas_Enroll_Teacher_In_Course.py 22222 me@institute.com
#
coursesisid = sys.argv[1]
teacheremail = sys.argv[2]
#load configs
home = Path.home() / ".ASAPCanvas" / "ASAPCanvas.json"
confighome = Path.home() / ".ASAPCanvas" / "ASAPCanvas.json"
with open(confighome) as f:
configs = json.load(f)
#-----Canvas Info
Canvas_API_URL = configs['CanvasAPIURL']
Canvas_API_KEY = configs['CanvasAPIKey']
#prep status (msg) and debug (dmsg) emails
canvas = Canvas(Canvas_API_URL, Canvas_API_KEY)
account = canvas.get_account(1)
print(coursesisid)
print(teacheremail)
try:
asapclass = canvas.get_course(coursesisid,use_sis_id=True)
except CanvasException as e:
if str(e) == "Not Found":
print('Error finding course')
print(str(e))
exit()
try:
user = canvas.get_user(teacheremail,'sis_login_id')
except CanvasException as e:
if str(e) == "Not Found":
print('Error finding course')
print(str(e))
exit()
try:
enrollment = asapclass.enroll_user(user.id, "TeacherEnrollment",
enrollment = {
"sis_course_id": coursesisid,
"notify": True,
"enrollment_state": "active"
}
)
except CanvasException as e:
if str(e) == "Not Found":
print('Error finding course')
print(str(e))
exit()
print('Enrolled teacher in class')