You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a script that uploads comments to a specific assignment based on the course_id, user_id, etc. I know there is an
endpoint] (v1/courses/{course_id}/assignments/{assignment_id}/submissions/{user_id}) that returns information about the submission comments field. Is there a way to check to see if comments have been added to a particular assignment before, say, I upload comments in my script?
I don't think canvasapi has any function in the Submission class that would allow me to not produce duplicate comments uploaded to a student assignment. There is an "edit" function and also a "get_submission_peer_reviews" but I'm not sure the latter returns the data I would need.
Obviously, the script now doesn't have this check, so, as it stands currently, it'll just upload duplicate comments if I were to run the script more than once (say, by error).
My apologies ahead of time if there is a way to get this data and I just missed it. (Also, if this is a duplicate here in the issues arena, feel free to let me know that too!)
Thanks to everyone there that works on this repository—it's been a hugely significant for me and my workflows, that's for sure!
The text was updated successfully, but these errors were encountered:
As you mentioned, when you upload a comment in a submission with canvas_submission.edit, a submission object is returned and it includes a list of submission_comments. This list appears to be sorted by the created_at key of each comment, so you can grab all the information about your newly uploaded comment by accessing submission_comments[-1]. One of the keys is the Canvas id of the comment, which uniquely identifies it.
Now your script to avoid uploading duplicates really depends on your implementation of a Comment.
Assuming that you have something like:
class Comment():
def __init__(self, text: str):
self.text = text
self.canvas_id = None
then you can first check if comment.canvas_id is None before you try uploading a particular comment, and update the canvas_id attribute after each successful comment upload. This of course requires that you somehow store these objects in some kind of a database so that these attributes persist when you run your upload script again. Of course, the comment that you have uploaded with your script in the past might have been deleted manually on Canvas, so something like:
for comment in my_stored_comments:
if comment.canvas_id is not None:
is_still_on_canvas = # your method that checks if a comment with id=comment.canvas_id is still in the submission
if is_still_on_canvas:
continue
newly_updated_submission = submission.edit(
comment = {"text_comment":comment.text})
new_comment_id_on_canvas = newly_updated_submission.submission_comments[-1]["id"]
comment.canvas_id = new_comment_id_on_canvas
To deal with the possibility that a comment might be edited manually on Canvas, you could check if the edited_at property of the comment is None.
If for some reason you don't want to store the canvas_id in your database, I think you could simply add a boolean property is_uploaded_to_canvas
I have a script that uploads comments to a specific assignment based on the course_id, user_id, etc. I know there is an
endpoint] (v1/courses/{course_id}/assignments/{assignment_id}/submissions/{user_id}) that returns information about the submission comments field. Is there a way to check to see if comments have been added to a particular assignment before, say, I upload comments in my script?
I don't think canvasapi has any function in the Submission class that would allow me to not produce duplicate comments uploaded to a student assignment. There is an "edit" function and also a "get_submission_peer_reviews" but I'm not sure the latter returns the data I would need.
Obviously, the script now doesn't have this check, so, as it stands currently, it'll just upload duplicate comments if I were to run the script more than once (say, by error).
My apologies ahead of time if there is a way to get this data and I just missed it. (Also, if this is a duplicate here in the issues arena, feel free to let me know that too!)
Thanks to everyone there that works on this repository—it's been a hugely significant for me and my workflows, that's for sure!
The text was updated successfully, but these errors were encountered: