Skip to content

Commit f5ee966

Browse files
added coursework snippets
1 parent 1385950 commit f5ee966

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

classroom/snippets/snippets.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,55 @@ def add_student(self):
213213
else:
214214
raise
215215
# [END classroom_add_student]
216+
217+
def create_coursework(self):
218+
"""
219+
Creates a coursework.
220+
"""
221+
service = self.service
222+
# [START classroom_create_coursework]
223+
courseWork = {
224+
'title': 'Ant colonies',
225+
'description': '''Read the article about ant colonies
226+
and complete the quiz.''',
227+
'materials': [
228+
{'link': {'url': 'http://example.com/ant-colonies'}},
229+
{'link': {'url': 'http://example.com/ant-quiz'}}
230+
],
231+
'workType': 'ASSIGNMENT',
232+
'state': 'PUBLISHED',
233+
}
234+
courseWork = service.courses().courseWork().create(
235+
courseId='123456', body=courseWork).execute()
236+
print('Assignment created with ID {%s}' % courseWork.get('id'))
237+
# [END classroom_create_coursework]
238+
239+
def list_submissions(self):
240+
"""
241+
Lists all student submissions for a given coursework.
242+
"""
243+
service = self.service
244+
# [START classroom_list_submissions]
245+
submissions = []
246+
page_token = None
247+
248+
while True:
249+
coursework = service.courses().courseWork()
250+
response = coursework.studentSubmissions().list(
251+
pageToken=page_token, courseId="123456",
252+
courseWorkId="654321").execute()
253+
submissions.extend(response.get('studentSubmissions', []))
254+
page_token = response.get('nextPageToken', None)
255+
if not page_token:
256+
break
257+
258+
if not submissions:
259+
print('No student submissions found.')
260+
else:
261+
print('Student Submissions:')
262+
for submission in submissions:
263+
print("%s was submitted at %s" %
264+
(submission.get('id'),
265+
submission.get('creationTime')))
266+
267+
# [END classroom_list_submissions]

0 commit comments

Comments
 (0)