Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Canvas Course Publishing Script, written by Luke Levesque - Liberty University*/
- # Written for use with python 2.7 and 'requests' package - http://docs.python-requests.org/en/ */
- import requests
- import time
- token = "YOUR TOKEN GOES HERE"
- account_id = 'ACCOUNT NUMBER YOUR COURSES RESIDE IN'
- url = 'URL OF YOUR CANVAS INSTANCE'
- s = raw_input("Please enter the Course IDs to publish, separated by commas: ")
- courseid = map(int, s.split(','))
- totalcount = 0
- def checkurl(url): # Send a request to Canvas to check the course state
- t = requests.get(url, headers = {'Authorization': 'Bearer ' + '%s' % token})
- urlresponse = t.json()
- print "| " + str(urlresponse[u'message']) + " |"
- for id in courseid: # Loop through the course IDs and send a request to publish each
- payload = {'course_ids[]': id, 'event': 'offer' }
- r = requests.put(url + '/api/v1/accounts/'+ str(account_id) + '/courses', params=payload, headers = {'Authorization': 'Bearer ' + '%s' % token})
- data = r.json()
- print data[u'url']
- time.sleep(2)
- checkurl(data[u'url'])
- totalcount += 1
- print str(totalcount) + " of " + str(len(courseid)) + " published."
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement