I just found some Python code that I've used to pull a list of teachers into a CSV file. I'm not quite sure if I actually wrote this or not but I just tested it and it worked. It just asks which account you want to pull from so you supply it with the account ID and it will pull the courses in that account and the teachers associated with each one.
import csv, requests, time, json
from pprint import pprint
access_token = 'token here'
teachers_csv = 'teachers.csv'
baseUrl = 'https://yourinstitution.instructure.com/api/v1/accounts/'
header = {'Authorization' : 'Bearer ' + access_token}
payload = {}
def main():
log_time = str(time.asctime(time.localtime(time.time())))
get_courses()
def get_courses():
l = open(teachers_csv, 'w+')
l.write("course_id, course_name, teacher1, teacher2, teacher3" + "\n")
l.close()
account_id = raw_input("Enter Account ID:")
url = baseUrl + account_id + '/courses?include[]=teachers'
r = requests.get(url, headers = header, data = payload)
j = json.loads(r.text)
write_rows(j)
while r.links['current']['url'] != r.links['last']['url']:
r = requests.get(r.links['next']['url'], headers=header)
j = json.loads(r.text)
write_rows(j)
def write_rows(j):
count = 0
with open(teachers_csv, 'a') as log:
for course in j:
teachers=j[count]['teachers']
if j[count]['teachers']:
log.write(str(j[count]['id'])+ ',"' + str(j[count]['name'])+ '"')
pprint(str(j[count]['id'])+ ',"' + str(j[count]['name'])+ '"')
for teacher in teachers:
log.write("," + teacher["display_name"])
log.write("\n")
count +=1
if __name__ == "__main__": main()
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.