Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add way to get parent_id for profile comments #228

Closed
TheCommCraft opened this issue Aug 4, 2024 · 3 comments
Closed

Add way to get parent_id for profile comments #228

TheCommCraft opened this issue Aug 4, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@TheCommCraft
Copy link
Contributor

It would be beneficial to have this feature implemented.

@TimMcCool TimMcCool added the enhancement New feature or request label Aug 5, 2024
@banddans
Copy link

banddans commented Aug 6, 2024

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

@TheCommCraft
Copy link
Contributor Author

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

@banddans
Copy link

banddans commented Aug 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants