Spaces:
Runtime error
Runtime error
File size: 1,655 Bytes
cc93546 |
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 |
import requests
import json
# Replace these variables with your own information
access_token = 'YOUR_ACCESS_TOKEN'
course_id = '36263'
discussion_topic_id = '421517'
base_url = 'https://canvas.illinois.edu'
headers = {
'Authorization': f'Bearer {access_token}'
}
# Create a content export
export_url = f'{base_url}/api/v1/courses/{course_id}/content_exports'
export_params = {
'export_type': 'common_cartridge',
'skip_notifications': True,
'select': {
'discussion_topics': [discussion_topic_id]
}
}
export_response = requests.post(export_url, headers=headers, params=export_params)
if export_response.ok:
export_data = export_response.json()
export_id = export_data['id']
# Check the progress of the content export
progress_url = f'{base_url}/api/v1/progress/{export_id}'
progress_response = requests.get(progress_url, headers=headers)
if progress_response.ok:
progress_data = progress_response.json()
while progress_data['workflow_state'] not in ['completed', 'failed']:
progress_response = requests.get(progress_url, headers=headers)
progress_data = progress_response.json()
if progress_data['workflow_state'] == 'completed':
# Download the exported content
download_url = progress_data['url']
download_response = requests.get(download_url)
if download_response.ok:
# Save the exported content to a file
with open('discussion_topic_export.imscc', 'wb') as f:
f.write(download_response.content)
else:
print(f'Error: {export_response.text}')
|