-
Notifications
You must be signed in to change notification settings - Fork 1
/
DOE_Course_SIS.py
45 lines (35 loc) · 1.1 KB
/
DOE_Course_SIS.py
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
from canvasapi import Canvas
import config
import csv
canvas = Canvas(config.API_URL, config.API_KEY)
filename = "DOE_Account_Import.csv"
csv_file = open(filename, 'w')
csv_file.write('course_id,short_name,long_name,account_id,status\n')
line_count = 0
def buildLine(courseID, accountID):
#print(courseID)
try:
course = canvas.get_course(courseID, True)
line = courseID
line += ',' + course.course_code
line += ',' + course.name
line += ',' + accountID
line += ',active\n'
return line
except:
print("Course Not Found: " + str(courseID))
with open('all_dce_courses.csv', 'r', newline='') as course_list:
reader = csv.reader(course_list, delimiter=',')
for row in reader:
line_count += 1
if (line_count % 100) == 0:
print(line_count)
courseID = row[0]
accountID = row[1]
if courseID == "course_id":
print(courseID)
else:
line = buildLine(courseID, accountID)
# print(line)
if line != None:
csv_file.write(line)