Advertisement
Guest User

Python Canvas Create Migration

a guest
Jul 2nd, 2015
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import requests
  2.  
  3. token='your token here'
  4.  
  5. def migrateContents(old_course_id, new_course_id):
  6.     payload={'migration_type':'course_copy_importer','settings[source_course_id]': str(old_course), 'date_shift_options[remove_dates]': 'True'}
  7.     r = requests.post('https://xxxx.instructure.com/api/v1/courses/'+ str(new_course)+ '/content_migrations/', params=payload, headers = {'Authorization': 'Bearer ' + token})
  8.     data = r.json()
  9.     #print data
  10.     progress_url = data[u'progress_url']
  11.     print "Migration URL is: " + str(progress_url)
  12.  
  13.     progress = 0
  14.     while progress != 100:
  15.         progress_check = requests.get(progress_url, headers = {'Authorization': 'Bearer ' + token})
  16.         progress_result = progress_check.json()
  17.         print "Migration Status is: " + str(data[u'workflow_state']) + ", | progress: " + str(progress_result[u'completion']) + "%"
  18.         #print progress_result
  19.         progress = progress_result[u'completion']
  20.  
  21.         time.sleep(20)
  22.  
  23.         if progress_result[u'completion'] == 100:
  24.             print "------------------------------"
  25.             print "Migration completed."
  26.             break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement