TimMcCool / scratchattach

Scratch API wrapper with support for almost all site features, cloud requests framework and more
MIT License
174 stars 44 forks source link

Error when retrieving comments from a user's profile #182

Closed fenziie closed 4 weeks ago

fenziie commented 7 months ago

Hey Tim! I really love ScratchAttach, thanks so much for making it. However, I have ran into a problem I just can't seem to fix relating to getting the comments of a users profile. Whenever I try to do it (I am signed in so using the connect_user() method then the user.comments() method) it returns a 404 error. The scratch account is definitely valid. The error says "Repl not found." Would appreciate some help!

Code:

import scratchattach as scratch3
import requests

session = scratch3.login("zeep-bot", "******")
myuser = session.connect_user("zeeplockd")

myuser.follow()
comments = myuser.comments()
print(f"{comments}\n\n")

for message in comments:
    if 'Content' in message and 'how are you' in message['Content']:
        print(f"===\nFound the text in the content of a message.\nID: {message['CommentID']}\nUser: {message['User']}\n===")

        has_zeepbot_reply = False
        if 'Replies' in message:
            for reply in message['Replies']:
                if 'User' in reply and reply['User'] == 'zeep-bot':
                    has_zeepbot_reply = True
                    print("Found a reply from 'zeep-bot'.")
                    break  # Exit the loop if a previous reply is found

        if not has_zeepbot_reply:
            # Get user ID using the Scratch API
            print(message['User'])
            api_url = f"https://api.scratch.mit.edu/users/{message['User']}"
            response = requests.get(api_url)
            print(response)
            datares = response.json()
            myuser.reply_comment("Great thanks!", parent_id=message['CommentID'], commentee_id=datares['id'])

            break  # Exit the loop after posting the reply

Error:

{'message': 'Repl not found', 'name': 'NotFoundError', 'status': 404}
TimMcCool commented 7 months ago

Updating scratchattach to the most recent version (with pip install -U scratchattach) should really fix this problem