Comments (1)
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
from canvasapi.
Related Issues (20)
- New Quizzes
- New Quiz Items
- Docs: How to download/upload grades/Gradebook? HOT 1
- Error when a course access is restricted HOT 1
- canvas create conversation cannot set subject HOT 3
- Rework url structure to accommodate graphql and new quizzes endpoints
- Attach files when creating a new discussion topic
- Delete Group Pages
- Request timeouts
- Comments to submissions are always added to first attempt HOT 1
- Duplicate Assignment
- Include Initiator-Only Conversations in API Endpoint HOT 3
- arrow.ParserError does not exist in file canvas_object.py HOT 8
- File objects get attribute `content-type` which must be accessed through `getattr` HOT 2
- Creating Quiz Questions HOT 1
- Improve `PaginatedList` docs
- setuptools 71 w/ pytest: TypeError: canonicalize_version() unexpected keyword argument 'strip_trailing_zero' HOT 2
- Add API coverage for SmartSearch
- Allow sis_user_id on some endpoints
- Add API coverage for LTI resource links HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from canvasapi.