-
Notifications
You must be signed in to change notification settings - Fork 1
/
course_account_check.py
72 lines (56 loc) · 2.09 KB
/
course_account_check.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from canvasapi import Canvas
import config
import csv
canvas = Canvas(config.API_URL, config.API_KEY)
account_id_lst = []
write_file = input("What would you like to name your file? ")
csv_w_file = open(write_file, 'w')
csv_w_file.write('course_id,short_name,long_name\n')
line_count = 0
def get_subaccounts(account):
subaccounts = account.get_subaccounts(True) # Get all subaccounts in an account
for subaccount in subaccounts:
account_id_lst.append(subaccount.id)
def buildLine(course, account):
try:
line = str(course.id)
line += ',' + str(course.course_code)
line += ',' + str(course.name)
line += '\n'
return line
except:
print("Course Not Found: " + str(courseID))
def main():
account_id = input("Enter the root account ID: ")
account = canvas.get_account(account_id)
account_id_lst.append(account.id)
get_subaccounts(account)
print(account_id_lst)
print("\nAccount list has been built...\n")
with open('Proctorio_Courses.csv', 'r', newline='') as course_list:
reader = csv.reader(course_list, delimiter=',')
line_count = 0
for row in reader:
line_count += 1
if (line_count % 10) == 0:
print("Lines Processed: " + str(line_count))
course_id = row[1]
if course_id == "context_id":
print("***********************")
else:
#print(course_id)
course = canvas.get_course(course_id)
course_account_id = course.account_id
account = canvas.get_account(course_account_id)
if course.account_id in account_id_lst:
None
else:
line = buildLine(course, account)
# print(line)
if line != None:
csv_w_file.write(line)
print("*********\nThe Course " + course.name)
print("appears in Account " + str(account))
print("*********")
if __name__ == "__main__":
main()