Giter Club home page Giter Club logo

Comments (1)

IonMich avatar IonMich commented on September 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.