Discuss Scratch

mrcoat
Scratcher
100+ posts

scratchclient - A scratch API wrapper for python

vikkcd wrote:

139109 wrote:

How do I handle errors such as invalid variable name?
Also I'm having the same problem. I decided to switch the module I'm using to scratch2py
Ya I'm switching to something that doesn't require visual c++

My cartoon
Watch My Show!
I was gonna put an image of the studio but it didn't work.

Cool thing I made
when [Awesomeness v] > (100)
forever
play sound [Victory v] until done
set rotation style [The best style v]
go to [The party v]
end
javakid7171
Scratcher
26 posts

scratchclient - A scratch API wrapper for python

hi

JAVAKID7171
Sid72020123
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

mrcoat wrote:

vikkcd wrote:

139109 wrote:

How do I handle errors such as invalid variable name?
Also I'm having the same problem. I decided to switch the module I'm using to scratch2py
Ya I'm switching to something that doesn't require visual c++
Will you use scratchconnect or scratch2py?

Sid72020123
mrcoat
Scratcher
100+ posts

scratchclient - A scratch API wrapper for python

Sid72020123 wrote:

mrcoat wrote:

vikkcd wrote:

139109 wrote:

How do I handle errors such as invalid variable name?
Also I'm having the same problem. I decided to switch the module I'm using to scratch2py
Ya I'm switching to something that doesn't require visual c++
Will you use scratchconnect or scratch2py?
Not sure yet, I want to do a bit o research.

My cartoon
Watch My Show!
I was gonna put an image of the studio but it didn't work.

Cool thing I made
when [Awesomeness v] > (100)
forever
play sound [Victory v] until done
set rotation style [The best style v]
go to [The party v]
end
Sid72020123
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

mrcoat wrote:

Sid72020123 wrote:

mrcoat wrote:

vikkcd wrote:

139109 wrote:

How do I handle errors such as invalid variable name?
Also I'm having the same problem. I decided to switch the module I'm using to scratch2py
Ya I'm switching to something that doesn't require visual c++
Will you use scratchconnect or scratch2py?
Not sure yet, I want to do a bit o research.
Ok!

Sid72020123
hubblefam
Scratcher
45 posts

scratchclient - A scratch API wrapper for python

so when i run the thing to change a cloud variable the program does not give me an error but it does not do anything.
the code:
from scratchclient import ScratchSession
session = ScratchSession(“Hubblefam”, “#########”)
connection = session.create_cloud_connection(596965016)
connection.set_cloud_variable(“CLOUD”, 1)
@connection.on(“set”)
def on_set(variable):
print(variable.name, variable.value)
print(connection.get_cloud_variable(“CLOUD”))
Goldtabby
Scratcher
93 posts

scratchclient - A scratch API wrapper for python

I am just going to make my own Scratch/Python API Module….

when green flag clicked
say [I make good quality projects!]
think [most of the time...]
say [come check them out!]
This is my Site! Check it out!
This is my profile! Come follow me!


Wireframe ship pro here: https://scratch.mit.edu/projects/369638452/
vikkcd
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

Goldtabby wrote:

I am just going to make my own Scratch/Python API Module….
Good luck.

Coder, Animator, Artist
Love Michael Jackson and OK GO music.

forever
Fold Origami
Listen to Michael Jackson and OK GO
Play guitar
end
Chiroyce
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

For @dhuls since they asked here

# after logging in and connecting to project
@connection.on("set")
def on_set(variable):
    print(f'{variable.name} has been set to {variable.value}')
    # variable.name is the name of the variable that was changed
    # variable.value is the value the variable was set to

Last edited by Chiroyce (Nov. 10, 2021 06:22:51)








April Fools' topics:
New Buildings in Scratch's headquarters
Give every Scratcher an M1 MacBook Air
Scratch should let users edit other Scratchers' projects
Make a statue for Jeffalo
Scratch Tech Tips™
Make a Chiroyce statue emoji


<img src=“x” onerror=“alert('XSS vulnerability discovered')”>

this is a test sentence
Goldtabby
Scratcher
93 posts

scratchclient - A scratch API wrapper for python

vikkcd wrote:

Goldtabby wrote:

I am just going to make my own Scratch/Python API Module….
Good luck.
Not that heard, I already started

when green flag clicked
say [I make good quality projects!]
think [most of the time...]
say [come check them out!]
This is my Site! Check it out!
This is my profile! Come follow me!


Wireframe ship pro here: https://scratch.mit.edu/projects/369638452/
nini2009ph
Scratcher
87 posts

scratchclient - A scratch API wrapper for python

Data = session.get_user(“nini2009ph”).get_followers()
for i in Data:
print(i.username)
session.get_studio(30610675).invite_curator(i.username)


error: self.owner = data KeyError: ‘owner’

Last edited by nini2009ph (Nov. 12, 2021 17:21:54)

nini2009ph
Scratcher
87 posts

scratchclient - A scratch API wrapper for python

nini2009ph wrote:

Data = session.get_user(“nini2009ph”).get_followers()
for i in Data:
print(i.username)
session.get_studio(30610675).invite_curator(i.username)


error: self.owner = data KeyError: ‘owner’
i did something in the scratch client code and now it works
Shawn12344
Scratcher
5 posts

scratchclient - A scratch API wrapper for python

Hello can i get some help with an error i keep getting. the error i get is websocket._exceptions.websocketconnectionclosedexception: connection to remote host was lost. i get the error after my code has been running for about 10+ hours.
JackK211424
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

Shawn12344 wrote:

Hello can i get some help with an error i keep getting. the error i get is websocket._exceptions.websocketconnectionclosedexception: connection to remote host was lost. i get the error after my code has been running for about 10+ hours.
I'm pretty sure that scratch closes the cloud connection after a time. The only way to fix this would be to use the Try: Except: anytime you use a request and if you get an error then reconnect.

vikkcd
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

right so scratch2py is too slow and is a bit too buggy for my liking. Lets try Scratch connect.

edit: so im stuck on the creating a connection with a project because I type in
HeadProject = ServerUser.connect_project(project_id=586832024)
and it keeps telling me that the project doesn't exist even though it does.

Last edited by vikkcd (Nov. 14, 2021 15:11:58)


Coder, Animator, Artist
Love Michael Jackson and OK GO music.

forever
Fold Origami
Listen to Michael Jackson and OK GO
Play guitar
end
ajsya
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

vikkcd wrote:

right so scratch2py is too slow and is a bit too buggy for my liking. Lets try Scratch connect.

edit: so im stuck on the creating a connection with a project because I type in
HeadProject = ServerUser.connect_project(project_id=586832024)
and it keeps telling me that the project doesn't exist even though it does.
You might need to share the project…

Feel free to message me on my profile if you need to tell me something/want someone to talk to.

Hi, I'm ajsya!

| GitHub | Wiki | My Posts |

Before creating a new topic on the forums search Ocular to see if one already exists!ˇ
vikkcd
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

ajsya wrote:

vikkcd wrote:

right so scratch2py is too slow and is a bit too buggy for my liking. Lets try Scratch connect.

edit: so im stuck on the creating a connection with a project because I type in
HeadProject = ServerUser.connect_project(project_id=586832024)
and it keeps telling me that the project doesn't exist even though it does.
You might need to share the project…
sure

Coder, Animator, Artist
Love Michael Jackson and OK GO music.

forever
Fold Origami
Listen to Michael Jackson and OK GO
Play guitar
end
-EmeraldThunder-
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

I've been making a pfp loader and have stumbled across a problem. The connection times out and gives me an error I would normally like to catch this error using a try statement and restart the main function although I am only using one function tied to the @connection.on('set') decorator. How can I catch a timeout and cause a restart.
@connection.on('set')
def main(variable):
    if variable.name[2:] == "Request":
        print(f'Received: {variable.value}')
        pfp = requests.get(f'https://api.scratch.mit.edu/users/{decode(variable.value)[0]}/').json()['profile']['images']['60x60']
        image = Image.open(requests.get(pfp, stream=True).raw)
        width, height = image.size
        values = list(image.getdata())
        send(values, width, height)
        connection.set_cloud_variable('Serving', int(connection.get_cloud_variable('Serving')) + 1)

Nothing here.
ajsya
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

-EmeraldThunder- wrote:

I've been making a pfp loader and have stumbled across a problem. The connection times out and gives me an error I would normally like to catch this error using a try statement and restart the main function although I am only using one function tied to the @connection.on('set') decorator. How can I catch a timeout and cause a restart.
@connection.on('set')
def main(variable):
    if variable.name[2:] == "Request":
        print(f'Received: {variable.value}')
        pfp = requests.get(f'https://api.scratch.mit.edu/users/{decode(variable.value)[0]}/').json()['profile']['images']['60x60']
        image = Image.open(requests.get(pfp, stream=True).raw)
        width, height = image.size
        values = list(image.getdata())
        send(values, width, height)
        connection.set_cloud_variable('Serving', int(connection.get_cloud_variable('Serving')) + 1)
wouldn't you do:
try:
  #your function
except TimeoutError:
  #do function again or whatever else here
should be something like that

Last edited by ajsya (Nov. 14, 2021 16:15:03)


Feel free to message me on my profile if you need to tell me something/want someone to talk to.

Hi, I'm ajsya!

| GitHub | Wiki | My Posts |

Before creating a new topic on the forums search Ocular to see if one already exists!ˇ
Sid72020123
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

vikkcd wrote:

ajsya wrote:

vikkcd wrote:

right so scratch2py is too slow and is a bit too buggy for my liking. Lets try Scratch connect.

edit: so im stuck on the creating a connection with a project because I type in
HeadProject = ServerUser.connect_project(project_id=586832024)
and it keeps telling me that the project doesn't exist even though it does.
You might need to share the project…
sure
Yes! The project needs to be shared.

Sid72020123

Powered by DjangoBB