Skip to content

Commit

Permalink
bullet-proof missing_grade.py
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus committed Nov 21, 2024
1 parent be2cdd2 commit d619654
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tools/missing_grade.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Script to find assignments which have not been graded
# Filename: missing_grade.py
import json, os
import argparse, requests
Expand Down Expand Up @@ -34,26 +35,30 @@ def task_to_set(task_name, canvas_set):
def get_group_categories():
url = "{0}/api/v1/courses/{1}/group_categories".format(CANVAS_URL, CANVAS_COURSE_ID)
r = requests.get(url, headers={'Authorization': 'Bearer ' + CANVAS_TOKEN})
if 'next' in r.links: raise Exception("need to implement paging")
return {group["name"]: group["id"] for group in json.loads(r.content)}


# Get assignments -> name : id
def get_assignments():
url = "{0}/api/v1/courses/{1}/assignments".format(CANVAS_URL, CANVAS_COURSE_ID)
r = requests.get(url, headers={'Authorization': 'Bearer ' + CANVAS_TOKEN})
if 'next' in r.links: raise Exception("need to implement paging")
return {assignment["name"]: assignment["id"] for assignment in json.loads(r.content)}


# Get groups in a group set -> name : id
def list_groups(id_group_category):
url = "{0}/api/v1/group_categories/{1}/groups?per_page=200".format(CANVAS_URL, id_group_category)
r = requests.get(url, headers={'Authorization': 'Bearer ' + CANVAS_TOKEN})
if 'next' in r.links: raise Exception("need to implement paging")
return {group["name"]: group["id"] for group in json.loads(r.content)}

# Get groups members -> name : id
def get_group_members(id_group):
url = "{0}/api/v1/groups/{1}/users".format(CANVAS_URL, id_group)
r = requests.get(url, headers={'Authorization': 'Bearer ' + CANVAS_TOKEN})
if 'next' in r.links: raise Exception("need to implement paging")
return {member["name"]: member["id"] for member in json.loads(r.content)}


Expand All @@ -76,7 +81,8 @@ def check_group_grading(groups, id_assignment):

# {'include[]': "submission_comments"} is a non-documented flag provided by colleague Chip Maguire
r = requests.get(canvas_url, headers={'Authorization': 'Bearer ' + CANVAS_TOKEN}, params = {'include[]': "submission_comments"})

if 'next' in r.links: raise Exception("need to implement paging")

comments = [x for x in r.json()["submission_comments"]]

last_comment = comments[-1]["comment"] if len(comments)>0 else ""
Expand Down

0 comments on commit d619654

Please sign in to comment.