Added ability to download all submissiosn from students and load credentials from file #1
58
export.py
58
export.py
|
@ -1,11 +1,14 @@
|
||||||
from canvasapi import Canvas
|
# built in
|
||||||
import requests
|
|
||||||
import traceback
|
|
||||||
import jsonpickle
|
|
||||||
import json
|
import json
|
||||||
import dateutil.parser
|
|
||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
# external
|
||||||
|
from canvasapi import Canvas
|
||||||
|
import dateutil.parser
|
||||||
|
import jsonpickle
|
||||||
|
import requests
|
||||||
|
|
||||||
# Canvas API URL
|
# Canvas API URL
|
||||||
API_URL = ""
|
API_URL = ""
|
||||||
|
@ -13,16 +16,19 @@ API_URL = ""
|
||||||
API_KEY = ""
|
API_KEY = ""
|
||||||
# My Canvas User ID
|
# My Canvas User ID
|
||||||
USER_ID = 0000000
|
USER_ID = 0000000
|
||||||
# Directory in which to download course information to (will be created if not present)
|
# Directory in which to download course information to (will be created if not
|
||||||
|
# present)
|
||||||
DL_LOCATION = "./output"
|
DL_LOCATION = "./output"
|
||||||
# List of Course IDs that should be skipped (need to be integers)
|
# List of Course IDs that should be skipped (need to be integers)
|
||||||
COURSES_TO_SKIP = [288290, 512033]
|
COURSES_TO_SKIP = [288290, 512033]
|
||||||
|
|
||||||
|
|
||||||
class moduleItemView():
|
class moduleItemView():
|
||||||
title = ""
|
title = ""
|
||||||
content_type = ""
|
content_type = ""
|
||||||
external_url = ""
|
external_url = ""
|
||||||
|
|
||||||
|
|
||||||
class moduleView():
|
class moduleView():
|
||||||
name = ""
|
name = ""
|
||||||
items = []
|
items = []
|
||||||
|
@ -30,17 +36,20 @@ class moduleView():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.items = []
|
self.items = []
|
||||||
|
|
||||||
|
|
||||||
class pageView():
|
class pageView():
|
||||||
title = ""
|
title = ""
|
||||||
body = ""
|
body = ""
|
||||||
created_date = ""
|
created_date = ""
|
||||||
last_updated_date = ""
|
last_updated_date = ""
|
||||||
|
|
||||||
|
|
||||||
class topicReplyView():
|
class topicReplyView():
|
||||||
author = ""
|
author = ""
|
||||||
posted_date = ""
|
posted_date = ""
|
||||||
body = ""
|
body = ""
|
||||||
|
|
||||||
|
|
||||||
class topicEntryView():
|
class topicEntryView():
|
||||||
author = ""
|
author = ""
|
||||||
posted_date = ""
|
posted_date = ""
|
||||||
|
@ -50,6 +59,7 @@ class topicEntryView():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.topic_replies = []
|
self.topic_replies = []
|
||||||
|
|
||||||
|
|
||||||
class discussionView():
|
class discussionView():
|
||||||
title = ""
|
title = ""
|
||||||
author = ""
|
author = ""
|
||||||
|
@ -60,22 +70,33 @@ class discussionView():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.topic_entries = []
|
self.topic_entries = []
|
||||||
|
|
||||||
|
|
||||||
class submissionView():
|
class submissionView():
|
||||||
grade = ""
|
grade = ""
|
||||||
raw_score = ""
|
raw_score = ""
|
||||||
total_possible_points = ""
|
total_possible_points = ""
|
||||||
submission_comments = ""
|
submission_comments = ""
|
||||||
|
user_id = None # integer
|
||||||
|
attachments = []
|
||||||
|
|
||||||
|
|
||||||
|
class attachmentView():
|
||||||
|
filename = ""
|
||||||
|
url = ""
|
||||||
|
|
||||||
|
|
||||||
class assignmentView():
|
class assignmentView():
|
||||||
title = ""
|
title = ""
|
||||||
description = ""
|
description = ""
|
||||||
assigned_date = ""
|
assigned_date = ""
|
||||||
due_date = ""
|
due_date = ""
|
||||||
|
submissions = {}
|
||||||
submission = None
|
submission = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.submission = submissionView()
|
self.submission = submissionView()
|
||||||
|
|
||||||
|
|
||||||
class courseView():
|
class courseView():
|
||||||
term = ""
|
term = ""
|
||||||
course_code = ""
|
course_code = ""
|
||||||
|
@ -89,6 +110,7 @@ class courseView():
|
||||||
self.announcements = []
|
self.announcements = []
|
||||||
self.discussions = []
|
self.discussions = []
|
||||||
|
|
||||||
|
|
||||||
def makeValidFilename(input_str):
|
def makeValidFilename(input_str):
|
||||||
# Remove invalid characters
|
# Remove invalid characters
|
||||||
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
|
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
|
||||||
|
@ -99,6 +121,7 @@ def makeValidFilename(input_str):
|
||||||
|
|
||||||
return input_str
|
return input_str
|
||||||
|
|
||||||
|
|
||||||
def findCourseModules(course, course_view):
|
def findCourseModules(course, course_view):
|
||||||
modules_dir = DL_LOCATION + "/" + course_view.term + "/" + course_view.course_code + "/modules"
|
modules_dir = DL_LOCATION + "/" + course_view.term + "/" + course_view.course_code + "/modules"
|
||||||
|
|
||||||
|
@ -261,15 +284,20 @@ def findCourseAssignments(course):
|
||||||
print("Got no submissions for this assignment")
|
print("Got no submissions for this assignment")
|
||||||
else:
|
else:
|
||||||
print(submissions)
|
print(submissions)
|
||||||
for submission in submissions:
|
for submission in submissions:
|
||||||
print(submission)
|
print(submission)
|
||||||
try:
|
sub_view = submissionView()
|
||||||
submission.attachments
|
try:
|
||||||
except AttributeError:
|
submission.attachments
|
||||||
print('No attachements')
|
except AttributeError:
|
||||||
else:
|
print('No attachments')
|
||||||
for attachment in submission.attachments:
|
else:
|
||||||
print(attachment["url"])
|
for attachment in submission.attachments:
|
||||||
|
attach_view = attachmentView()
|
||||||
|
attach_view.url = attachment.url
|
||||||
|
attach_view.filename = attachment.filename
|
||||||
|
sub_view.attachments.append
|
||||||
|
print(attachment["url"])
|
||||||
|
|
||||||
# Get my user"s submission object
|
# Get my user"s submission object
|
||||||
submission = assignment.get_submission(USER_ID)
|
submission = assignment.get_submission(USER_ID)
|
||||||
|
|
Loading…
Reference in New Issue