Discuss Scratch

zaid1442011
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Nevermind, it was just trubowarp refusing my connection or something.
MonkeyBean2
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

zaid1442011 wrote:

MonkeyBean2 wrote:

(#2683)
No offense, but this is not a great way to do this. It will spam turbowarp with unnecessary updates (unless scratchattach prevents changing a cloud variable that's already been changed, that could cause problems though). Plus, .get_cloud() is depreciated now, and does not work in the latest version of scratchattach, and even if you are using an older version that supports this I think you might need to connect to the scratch cloud server first.

You can update scratchattach to the latest version with
pip install scratchattach --upgrade
in your terminal.

A better way to do this would be to open up the websocket connection to scratch yourself, and call .recv(), something like this: (untested, tell me if it doesn't work)

#Import modules
import scratchattach as scratch3
from dotenv import load_dotenv
import os
import time #To add rate limiter
import websocket # websocket-client
import json
#Load the .env file(s)
load_dotenv('app.env')
#Set variables to the enviroment variables
sessionID=os.getenv('sessionID')
username=os.getenv('username')
scratch_project=os.getenv('scratch_project')
server=os.getenv('cloud_host')
# Log into scratch
session = scratch3.Session(sessionID, username=username)
# Connect to scratch cloud server
ws = websocket.WebSocket()
ws.connect(
    "wss://clouddata.scratch.mit.edu",
    cookie="scratchsessionsid=" + session.session_id + ";",
    origin="https://scratch.mit.edu",
    enable_multithread=True
)
# Connect to Turbowarp or another cloud server
turbo_conn = scratch3.TwCloudConnection(project_id=scratch_project, username=username, cloud_host=server, purpose="A test for a bot that syncs Scratch variables to another cloud server", contact="zaid1442011 on scratch and [redacted]")
while True:
    msgs = ws.recv().split('\n')
    for msg in msgs:
        if len(msg) == 0:
            continue
        parsed = json.loads(msg)
        if parsed['method'] == 'set':
            # Sets the variable in Turbowarp
            turbo_conn.set_var(parsed['name'][4:], parsed['value'])
            time.sleep(0.1) # Rate limiter (might not be needed)


(@TimMcCool, is there a better way of doing this? maybe cloud requests idk)

After some troubleshooting, it seams that the problem is with the TwCloudConnection function. The .get_cloud() works with no issues. I even tried to do the same thing but use scratchcommunication to set the variables (It works, but not with Turbowarp's cloud server).
Yeah, it seems like you simply can't get previous values of cloud variables in scratch without querying the cloud logs (and even then that won't always work).
TimMcCool
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

AlexDF16 wrote:

Okay, I KEEP getting messages about this forum. Why is this?
:|
move (100000000000000000000000000000000000000000000000000000) steps
That means you're following this discussion
dynamicsofscratch
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

TimMcCool wrote:

(#2690)

AlexDF16 wrote:

Okay, I KEEP getting messages about this forum. Why is this?
:|
move (100000000000000000000000000000000000000000000000000000) steps
That means you're following this discussion
lol
zaid1442011
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Does Turbowarp's cloud server block connections from cloud bots or I forgot to add something?
TimMcCool
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

In the past, many people reported they were unable to connect to Scratch's cloud variables because they got this error:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)

I was never able to reproduce the error - until I recently stumbled upon it myself on a new device. I found a way to fix it which will be implemented in scratchattach soon / in a future update.
elip100
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

(#2692)
session.get_message_count() should definitely exist…
    session.get_message_count()
    ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Session' object has no attribute 'get_message_count'. Did you mean: 'message_count'?
(´・ω・`)

This should work:
session.get_linked_user().message_count()
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.
TimMcCool
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

wvzack wrote:

Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.
putting client.run(no_packet_loss=True) might fix this

Last edited by TimMcCool (Aug. 5, 2024 03:22:55)

zaid1442011
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

I found I suffered all of this time because the EU instance of Turbowarp's cloud server is down.
Da-thing
Scratcher
73 posts

scratchattach - A Scratch API wrapper (Python)

goldtime9 wrote:

how do you guys make that
It's mostly just the Scratch API HTTP requests tied up into a package.
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

Does anyone know how to use Scratchattach to log in and operate with multiple accounts?
login with 2 variables ex:
session = scratch3.login(“username”, “password”)
session2 = scratch3.login(“username2”, “password”)
then latter use session or session2 depending on what account you want to use.
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

TimMcCool wrote:

wvzack wrote:

Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.
putting client.run(no_packet_loss=True) might fix this
do I place this at the bottom of the script replacing the client.run()?
elip100
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

wvzack wrote:

(#2704)

TimMcCool wrote:

wvzack wrote:

Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.
putting client.run(no_packet_loss=True) might fix this
do I place this at the bottom of the script replacing the client.run()?
Yes replace client.run() with
client.run(no_packet_loss=True)
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

elip100 wrote:

wvzack wrote:

(#2704)

TimMcCool wrote:

wvzack wrote:

Just a little thing I thought I should say: sometimes my project will say the servers down because the server is not returning anything though on the server script side it’s printing out the right thing.
putting client.run(no_packet_loss=True) might fix this
do I place this at the bottom of the script replacing the client.run()?
Yes replace client.run() with
client.run(no_packet_loss=True)
okay thanks!
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

wvzack wrote:

Black-takashi_01 wrote:

-snip

cool I would of never thought of that though I have never used .append soo i have no idea how you would use that.
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

I am getting so many login errors.
uhhhhhm…
yeah same I keep getting xtoken errors or it just fails to log in
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

I want to make my scratchattach project work on turbowarp where you can enter a password but i am not sure if it is possible to view/ decode the cloud data logs which would make it easy to find other peoples passwords.
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

wvzack wrote:

I want to make my scratchattach project work on turbowarp where you can enter a password but i am not sure if it is possible to view/ decode the cloud data logs which would make it easy to find other peoples passwords.

conn = session.connect_tw_cloud(“project_id”)
value = scratch3.get_tw_var(“project_id”, “variable”, purpose=“your use case (optional)”, contact=“your Scratch account or other contact info (optional)”)
variables = scratch3.get_tw_cloud(“project_id”, purpose=“your use case (optional)”, contact=“your Scratch account or other contact info (optional)”)
what i mean was i wasent sure if it would be possible for people to see turbowarps data logs and then decode your passcode
redspacecat
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

wvzack wrote:

Black-takashi_01 wrote:

wvzack wrote:

I want to make my scratchattach project work on turbowarp where you can enter a password but i am not sure if it is possible to view/ decode the cloud data logs which would make it easy to find other peoples passwords.

conn = session.connect_tw_cloud(“project_id”)
value = scratch3.get_tw_var(“project_id”, “variable”, purpose=“your use case (optional)”, contact=“your Scratch account or other contact info (optional)”)
variables = scratch3.get_tw_cloud(“project_id”, purpose=“your use case (optional)”, contact=“your Scratch account or other contact info (optional)”)
what i mean was i wasent sure if it would be possible for people to see turbowarps data logs and then decode your passcode
TurboWarp doesn't have accessible cloud logs and also you aren't putting your password in there. (Unless I'm misunderstanding)

Powered by DjangoBB