Advertisement
Guest User

Canvas Course Publishing Script

a guest
Jun 22nd, 2015
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. # Canvas Course Publishing Script, written by Luke Levesque - Liberty University*/
  2. # Written for use with python 2.7 and 'requests' package - http://docs.python-requests.org/en/ */
  3.  
  4. import requests
  5. import time
  6.  
  7. token = "YOUR TOKEN GOES HERE"
  8.  
  9. account_id = 'ACCOUNT NUMBER YOUR COURSES RESIDE IN'
  10.  
  11. url = 'URL OF YOUR CANVAS INSTANCE'
  12.  
  13. s = raw_input("Please enter the Course IDs to publish, separated by commas: ")
  14.  
  15. courseid = map(int, s.split(','))
  16.  
  17. totalcount = 0
  18.  
  19. def checkurl(url): # Send a request to Canvas to check the course state
  20.     t = requests.get(url, headers = {'Authorization': 'Bearer ' + '%s' % token})
  21.     urlresponse = t.json()
  22.     print "| " + str(urlresponse[u'message']) + " |"
  23.    
  24. for id in courseid: # Loop through the course IDs and send a request to publish each
  25.     payload = {'course_ids[]': id, 'event': 'offer' }
  26.     r = requests.put(url + '/api/v1/accounts/'97825/courses', params=payload, headers = {'Authorization': 'Bearer ' + '%s' % token})
  27.     data = r.json()
  28.     print data[u'url']
  29.     time.sleep(2)
  30.     checkurl(data[u'url'])
  31.     totalcount += 1
  32.     print str(totalcount) + " of " + str(len(courseid)) + " published."
  33.     time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement