Added ability to download all submissiosn from students and load credentials from file #1
32
export.py
32
export.py
|
@ -15,8 +15,8 @@ API_KEY = ""
|
|||
USER_ID = 0000000
|
||||
# Directory in which to download course information to (will be created if not present)
|
||||
DL_LOCATION = "./output"
|
||||
# List of Course IDs that should be skipped
|
||||
COURSES_TO_SKIP = []
|
||||
# List of Course IDs that should be skipped (need to be integers)
|
||||
COURSES_TO_SKIP = [288290, 512033]
|
||||
|
||||
class moduleItemView():
|
||||
title = ""
|
||||
|
@ -182,6 +182,7 @@ def downloadCourseFiles(course, course_view):
|
|||
|
||||
# Download file if it doesn't already exist
|
||||
if not os.path.exists(dl_path):
|
||||
print('Downloading: {}'.format(dl_path))
|
||||
file.download(dl_path)
|
||||
except Exception as e:
|
||||
print("Skipping file download that gave the following error:")
|
||||
|
@ -240,6 +241,7 @@ def findCourseAssignments(course):
|
|||
assignments = course.get_assignments()
|
||||
|
||||
for assignment in assignments:
|
||||
print(assignment)
|
||||
# Create a new assignment view
|
||||
assignment_view = assignmentView()
|
||||
|
||||
|
@ -252,6 +254,23 @@ def findCourseAssignments(course):
|
|||
# Due date
|
||||
assignment_view.due_date = assignment.due_at_date.strftime("%B %d, %Y %I:%M %p") if hasattr(assignment, "due_at_date") else ""
|
||||
|
||||
# Download all submissions
|
||||
try:
|
||||
submissions = assignment.get_submissions()
|
||||
except:
|
||||
print("Got no submissions for this assignment")
|
||||
else:
|
||||
print(submissions)
|
||||
for submission in submissions:
|
||||
print(submission)
|
||||
try:
|
||||
submission.attachments
|
||||
except AttributeError:
|
||||
print('No attachements')
|
||||
else:
|
||||
for attachment in submission.attachments:
|
||||
print(attachment["url"])
|
||||
|
||||
# Get my user"s submission object
|
||||
submission = assignment.get_submission(USER_ID)
|
||||
|
||||
|
@ -268,6 +287,9 @@ def findCourseAssignments(course):
|
|||
assignment_view.submission.submission_comments = str(submission.submission_comments) if hasattr(submission, "submission_comments") else ""
|
||||
|
||||
assignment_views.append(assignment_view)
|
||||
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print("Skipping assignment that gave the following error:")
|
||||
print(e)
|
||||
|
@ -416,17 +438,17 @@ def main():
|
|||
# Canvas API URL
|
||||
print("We will need your organization's Canvas Base URL. This is probably something like https://{schoolName}.instructure.com)")
|
||||
global API_URL
|
||||
API_URL = input("Enter your organization's Canvas Base URL: ")
|
||||
#API_URL = input("Enter your organization's Canvas Base URL: ")
|
||||
|
||||
# Canvas API key
|
||||
print("\nWe will need a valid API key for your user. You can generate one in Canvas once you are logged in.")
|
||||
global API_KEY
|
||||
API_KEY = input("Enter a valid API key for your user: ")
|
||||
#API_KEY = input("Enter a valid API key for your user: ")
|
||||
|
||||
# My Canvas User ID
|
||||
print("\nWe will need your Canvas User ID. You can find this by logging in to canvas and then going to this URL in the same browser {yourCanvasBaseUrl}/api/v1/users/self")
|
||||
global USER_ID
|
||||
USER_ID = input("Enter your Canvas User ID: ")
|
||||
#USER_ID = input("Enter your Canvas User ID: ")
|
||||
|
||||
print("\nConnecting to canvas\n")
|
||||
|
||||
|
|
Loading…
Reference in New Issue