How to download student submissions for assignment? #634
-
Hi! I've enjoyed playing around with I apologize for broaching what I imagine is a very common question, but I haven't seen it covered on the Docs page https://canvasapi.readthedocs.io/en/stable/examples.html#assignments My question is: How do I (programmatically, in Python) download the files that students have submitted for an assignment? If I execute code such as canvas = Canvas(API_URL, API_KEY)
course = canvas.get_course(course_id)
assn_id = 1234
assignment = course.get_assignment(assn_id)
subs = assignment.get_submissions() .... it gives me a for s in subs:
print(s) I see a set of strings that read like ...But I'm not sure what to do after that! Since the list Can anyone help? Thanks. PS- In looking for answers, so far I've only found:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
...Ok. Insead I print for s in subs:
print(s.__dir__()) Then I see a list of attributes that reads
....not sure where the attached file is? If I print out Alternatively, by doing a test submission with "Test Student", I'm able to see that the syntax of the URL that forms for the file download is |
Beta Was this translation helpful? Give feedback.
-
Oooo! I got it! I could close this thread now, but perhaps I should leave it open in case wiser people want to chime in? ls = 0
for s in subs:
print(f"-----\nls={ls}")
if len(s.attachments) > 0:
thefile = s.attachments[-1]
thefile.download(f"a{s.assignment_id}_u{s.user_id}_{thefile}")
ls+= 1 This will download my students' submitted files to the current directory. Inspecting them locally shows that the files are intact! :-) Admins, feel free to close if you like. |
Beta Was this translation helpful? Give feedback.
Oooo! I got it! I could close this thread now, but perhaps I should leave it open in case wiser people want to chime in?
This will download my students' submitted files to the current directory. Inspecting them locally shows that the files are intact! :-)
Admins, feel free to close if you like.