scratchattach icon indicating copy to clipboard operation
scratchattach copied to clipboard

Add way to get parent_id for profile comments

Open TheCommCraft opened this issue 1 year ago • 3 comments

It would be beneficial to have this feature implemented.

TheCommCraft avatar Aug 04 '24 12:08 TheCommCraft

from bs4 import BeautifulSoup
import requests

def find_parent_id(comment_id, user):
    try:
        i = 0
        while True:
            data = requests.get(
                f"https://scratch.mit.edu/site-api/comments/user/{user}/?page=" + str(i)).text
            soup = BeautifulSoup(data, features="html.parser")
            comment = soup.find(id="comments-" + str(comment_id))
            if comment != None:
                return comment.parent.parent.parent.find(class_="comment")["data-comment-id"]
                break
            i += 1
    except AttributeError:
        return comment_id

banddans avatar Aug 06 '24 15:08 banddans

I know about that and TimMcCool likely also does. I am just suggesting it be implemented.

TheCommCraft avatar Aug 06 '24 17:08 TheCommCraft

Okay, I agree it should be good to implement :D

banddans avatar Aug 06 '24 18:08 banddans