Discuss Scratch

fries09
Scratcher
58 posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

What if, taking these concepts, you could make Scratch, Co-op mode! Each user would be able to make a co-op project, and work together with specific people they chose.

Hello.
<[My brain cells] < [-100]>
Mast_Scratch
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

-FreeEngines- wrote:

Mast_Scratch wrote:

TimMcCool wrote:

Mast_Scratch wrote:

Not all features I bet, I can't comment or reply or follow or unfollow or change the desc of studio or change the title of the studio or change the title of a project or change the instructions and notes of a project and etc.

P.S. I ain't using replit to test these I use VSCode
All of these features were tested and work. Are you getting any errors/warnings? Can we see your code?


Yes, certainly
import os
#os.system("pip install -U scratchattach")
import scratchattach as scratch3
session = scratch3.Session("PRIVATE", username="Mast_Scratch")
user = scratch3.get_user('Mast_Scratch')
user.reply_comment("TEST", parent_id="222584202")
project = scratch3.get_project("724856203")
project.download(filename="project_name.sb3", dir="/")
studio = session.connect_studio("30212213")
studio.follow()
you are replacing PRIVATE with a valid sessionid?


You are joking right!? Am I foolish enough to NOT write a valid session ID?! << instead of this long msg, YES


KROKOBIL
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

TimMcCool wrote:

infintyrussia wrote:

Can you now send long requests? Ones that exceed the cloud var limit?
Because I found this:

Just wondering because if so it would be beneficial.
Yes, you can! This was added in v1.0, I forgot to mention it here (thanks for reminding me).
The length limit for requests was removed - if a request is too long for one cloud variable, it will be split to multiple.
This doesn't work for me…
I use the newest Scratch project (from github) and scratchattach version 0.9.5 (setup.py). (Why isn't this 1.0 or higher?)
I use this code:
Send request | request name: [test] argument1: [HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloTEST] and wait :: custom
@client.request
def test(argument1):
    print(f"test {argument1}")
    return argument1
Output (Python):
test HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHe
This is because the “_ Prepare send of (data)” block has an error:
This has to be at the end of the block:
if <not <(\[requests]\[encoder] _temp output) = []>> then
add (\[requests]\[encoder] _temp output) to [(requests) to_send v]
set [(requests)(encoder) _temp output v] to []
end
When I changed this, the data is split into two variables and put in the cloud perfectly, but the python code doesn't work; it prints:
Warning: Client received an unknown request called 'GG;U:GG;U:GG'
(The last part is not always the same, it depends on what you send.)
This is the cloud data history when I send the code from above:
KROKOBIL	☁ TO_HOST	set	343493629434349362943434960305860.192330
KROKOBIL ☁ TO_HOST set -59295759963629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294.192330
Is it possible that my python code isn't up to date (It's the same version like the one on github: 0.9.5)???
(PROBLEM SOLVED)

Last edited by KROKOBIL (Sept. 12, 2022 05:14:47)

Senievol-PIayground
Scratcher
1 post

scratchattach - A Scratch API wrapper | v1.0 released (Python)

KROKOBIL wrote:

(#1204)
This doesn't work for me…
I use the newest Scratch project (from github) and scratchattach version 0.9.5 (setup.py). (Why isn't this 1.0 or higher?)
Is it possible that my python code isn't up to date (It's the same version like the one on github: 0.9.5)???
I'm pretty sure that functionnality was added in 1.0.
-FreeEngines-
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

KROKOBIL wrote:

TimMcCool wrote:

infintyrussia wrote:

Can you now send long requests? Ones that exceed the cloud var limit?
Because I found this:

Just wondering because if so it would be beneficial.
Yes, you can! This was added in v1.0, I forgot to mention it here (thanks for reminding me).
The length limit for requests was removed - if a request is too long for one cloud variable, it will be split to multiple.
This doesn't work for me…
I use the newest Scratch project (from github) and scratchattach version 0.9.5 (setup.py). (Why isn't this 1.0 or higher?)
I use this code:
Send request | request name: [test] argument1: [HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloTEST] and wait :: custom
@client.request
def test(argument1):
    print(f"test {argument1}")
    return argument1
Output (Python):
test HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHe
This is because the “_ Prepare send of (data)” block has an error:
This has to be at the end of the block:
if <not <(\[requests]\[encoder] _temp output) = []>> then
add (\[requests]\[encoder] _temp output) to [(requests) to_send v]
set [(requests)(encoder) _temp output v] to []
end
When I changed this, the data is split into two variables and put in the cloud perfectly, but the python code doesn't work; it prints:
Warning: Client received an unknown request called 'GG;U:GG;U:GG'
(The last part is not always the same, it depends on what you send.)
This is the cloud data history when I send the code from above:
KROKOBIL	☁ TO_HOST	set	343493629434349362943434960305860.192330
KROKOBIL ☁ TO_HOST set -59295759963629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294.192330
Is it possible that my python code isn't up to date (It's the same version like the one on github: 0.9.5)???
i'd recommend manually splitting the data, if tim hasnt aded that working yet
KROKOBIL
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

-FreeEngines- wrote:

KROKOBIL wrote:

i'd recommend manually splitting the data, if tim hasnt aded that working yet
He has added it yet.
KROKOBIL
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

KROKOBIL wrote:

TimMcCool wrote:

infintyrussia wrote:

Can you now send long requests? Ones that exceed the cloud var limit?
Because I found this:

Just wondering because if so it would be beneficial.
Yes, you can! This was added in v1.0, I forgot to mention it here (thanks for reminding me).
The length limit for requests was removed - if a request is too long for one cloud variable, it will be split to multiple.
This doesn't work for me…
I use the newest Scratch project (from github) and scratchattach version 0.9.5 (setup.py). (Why isn't this 1.0 or higher?)
I use this code:
Send request | request name: [test] argument1: [HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloTEST] and wait :: custom
@client.request
def test(argument1):
    print(f"test {argument1}")
    return argument1
Output (Python):
test HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHe
This is because the “_ Prepare send of (data)” block has an error:
This has to be at the end of the block:
if <not <(\[requests]\[encoder] _temp output) = []>> then
add (\[requests]\[encoder] _temp output) to [(requests) to_send v]
set [(requests)(encoder) _temp output v] to []
end
When I changed this, the data is split into two variables and put in the cloud perfectly, but the python code doesn't work; it prints:
Warning: Client received an unknown request called 'GG;U:GG;U:GG'
(The last part is not always the same, it depends on what you send.)
This is the cloud data history when I send the code from above:
KROKOBIL	☁ TO_HOST	set	343493629434349362943434960305860.192330
KROKOBIL ☁ TO_HOST set -59295759963629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294343493629434349362943434936294.192330
Is it possible that my python code isn't up to date (It's the same version like the one on github: 0.9.5)???
Solved:
The error was in scratch and/or my computer:

Scratch sends two request parts with 0.1 second delay. They are in the right order (with correct timestamp), but python first receives the second (newest) part and then both. I don't know why…

I have now solved the problem by increasing the wait time in the _
KROKOBIL
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

Please change this, @TimMcCool:
In the scratch project you have three Send request blocks. You could simplify this:
define Send request | request name: (\[request name]) and wait
... // don't change anything here

define Send request | request name: (\[request name]) argument1: (\[arg1]) and wait
Send request | request name: (join (\[request name]) (join [&] (\[arg1]))) and wait

define Send request | request name: (\[request name]) argument1: (\[arg1]) argument2: (\[arg2]) and wait
Send request | request name: (join (\[request name]) (join [&] (join (\[arg1]) (join [&] (\[arg2]))))) and wait
KROKOBIL
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

Is it possible to have more than one project with cloud requests in one python script? Because you can call the run() function only once…
ZZC12345
Scratcher
500+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

KROKOBIL wrote:

Is it possible to have more than one project with cloud requests in one python script? Because you can call the run() function only once…
You should use threads to achieve this, as I think ScratchAttach constantly polls Scratch's servers on the main thread.

This is my signature. Contrary to popular belief, you do not need scratchblocks to protect against evil kumquats.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Make sure to check out these cool projects, written in real code!
Aviate - Itinerary - Scratch Auth - Orange OS Linux Distro - ocular - Leopard - PyHelp
DifferentDance8
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

ZZC12345 wrote:

KROKOBIL wrote:

Is it possible to have more than one project with cloud requests in one python script? Because you can call the run() function only once…
You should use threads to achieve this, as I think ScratchAttach constantly polls Scratch's servers on the main thread.
In fact, threads are encouraged in any usage that needs to be ran multiple times at once.

(removed by myself - this signature is far too long for any normal human being to read)

thirteenoclock wrote:

every 60 seconds, a minute passes. please fund my fight to slow time so we can prevent this. thank you
JloAu
Scratcher
18 posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

Hello I'm learning to use Scratchattach.
I think it's the best Scratch API, there is a lot of features and possibilities. Congrats for this .

I have a problem with the user.post_comment(“this is a comment”, parent_id=“”, commentee_id=“”) function… I can't post comment and it's the same with thing with project.post_comment(content=“this is a comment”, parent_id=“”, commentee_id=“”)

Notice that i'm logged in with session = scratch3.login(“JloAu”, “password”) and user = user.get_user('JloAu') and got a project with project = scratch3.get_project(“1234567890”)

I don't know how to fix, can anyone help me?

Thanks a lot

EDIT: I tried to post a comment by entering line per line the commands in the python console, then the response of user.post_comment() function is (is the error 403 access denied ?) Maybe we can't send comments using APIs…

Last edited by JloAu (Sept. 12, 2022 19:17:07)


JloAu
My most famous project : ScratchOS
And my best project : ScratchOS 3.0
Learning to use ScratchAttach
-FreeEngines-
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

JloAu wrote:

Hello I'm learning to use Scratchattach.
I think it's the best Scratch API, there is a lot of features and possibilities. Congrats for this .

I have a problem with the user.post_comment(“this is a comment”, parent_id=“”, commentee_id=“”) function… I can't post comment and it's the same with thing with project.post_comment(content=“this is a comment”, parent_id=“”, commentee_id=“”)

Notice that i'm logged in with session = scratch3.login(“JloAu”, “password”) and user = user.get_user('JloAu') and got a project with project = scratch3.get_project(“1234567890”)

I don't know how to fix, can anyone help me?

Thanks a lot

EDIT: I tried to post a comment by entering line per line the commands in the python console, then the response of user.post_comment() function is (is the error 403 access denied ?) Maybe we can't send comments using APIs…
sending comments using api's is just fine. 403 is most likely returned because you have not sent a valid sessionid.
are you using any online ide or runnning it on your computer?
does the project actually exist / is it shareed? (also i am unsure about user = user.get_user(“”) and some overwriting..) at this point it just a blank theoreie but i think yuo post commentest with session.post_comment or atleast get_user is used in some context with the session, im gonna read the github rq
-FreeEngines-
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

JloAu wrote:

Hello I'm learning to use Scratchattach.
I think it's the best Scratch API, there is a lot of features and possibilities. Congrats for this .

I have a problem with the user.post_comment(“this is a comment”, parent_id=“”, commentee_id=“”) function… I can't post comment and it's the same with thing with project.post_comment(content=“this is a comment”, parent_id=“”, commentee_id=“”)

Notice that i'm logged in with session = scratch3.login(“JloAu”, “password”) and user = user.get_user('JloAu') and got a project with project = scratch3.get_project(“1234567890”)

I don't know how to fix, can anyone help me?

Thanks a lot

EDIT: I tried to post a comment by entering line per line the commands in the python console, then the response of user.post_comment() function is (is the error 403 access denied ?) Maybe we can't send comments using APIs…
ok, i have foud the problem.
you are using
user = get_user() but this just gets the user and his stats etc. but you wanna use user = session.connect_user(“username”) which basically sets the user to the given username (replace “username” with your username obviously) this should entirely fix it
JloAu
Scratcher
18 posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

-FreeEngines- wrote:

JloAu wrote:

Hello I'm learning to use Scratchattach.
I think it's the best Scratch API, there is a lot of features and possibilities. Congrats for this .

I have a problem with the user.post_comment(“this is a comment”, parent_id=“”, commentee_id=“”) function… I can't post comment and it's the same with thing with project.post_comment(content=“this is a comment”, parent_id=“”, commentee_id=“”)

Notice that i'm logged in with session = scratch3.login(“JloAu”, “password”) and user = user.get_user('JloAu') and got a project with project = scratch3.get_project(“1234567890”)

I don't know how to fix, can anyone help me?

Thanks a lot

EDIT: I tried to post a comment by entering line per line the commands in the python console, then the response of user.post_comment() function is (is the error 403 access denied ?) Maybe we can't send comments using APIs…
ok, i have foud the problem.
you are using
user = get_user() but this just gets the user and his stats etc. but you wanna use user = session.connect_user(“username”) which basically sets the user to the given username (replace “username” with your username obviously) this should entirely fix it

Hello, thank you for replying faster! Indeed I was trying with the wrong command! I'll try it this evening after high school, I hope it will work

Thanks again for your help

JloAu
My most famous project : ScratchOS
And my best project : ScratchOS 3.0
Learning to use ScratchAttach
JloAu
Scratcher
18 posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

@-FreeEngines- Now I can post on my profile and on my project! But I can't reply… I get these 2 responses:
1) {'rejected': ‘isFlood’, ‘status’: {}}
or
2) {'id': 288398259, ‘parent_id’: 288365875, ‘commentee_id’: None, ‘content’: ‘I do not sorry’, ‘datetime_created’: ‘2022-09-13T14:05:07.000Z’, ‘datetime_modified’: ‘2022-09-13T14:05:07.000Z’, ‘visibility’: ‘visible’, ‘author’: {'id': 50609461, ‘username’: ‘JloAu’, ‘scratchteam’: False, ‘image’: 'https://cdn2.scratch.mit.edu/get_image/user/50609461_60x60.png'}, ‘reply_count’: 0}

In the 2 cases the comment doesn't appears on the website…

JloAu
My most famous project : ScratchOS
And my best project : ScratchOS 3.0
Learning to use ScratchAttach
TimMcCool
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

KROKOBIL wrote:

The error was in scratch and/or my computer:

Scratch sends two request parts with 0.1 second delay. They are in the right order (with correct timestamp), but python first receives the second (newest) part and then both. I don't know why…

I have now solved the problem by increasing the wait time in the _
That's interesting. Thanks for figuring out the problem. I'll fix it soon

JloAu wrote:

@-FreeEngines- Now I can post on my profile and on my project! But I can't reply… I get these 2 responses:
1) {'rejected': ‘isFlood’, ‘status’: {}}
or
2) {'id': 288398259, ‘parent_id’: 288365875, ‘commentee_id’: None, ‘content’: ‘I do not sorry’, ‘datetime_created’: ‘2022-09-13T14:05:07.000Z’, ‘datetime_modified’: ‘2022-09-13T14:05:07.000Z’, ‘visibility’: ‘visible’, ‘author’: {'id': 50609461, ‘username’: ‘JloAu’, ‘scratchteam’: False, ‘image’: 'https://cdn2.scratch.mit.edu/get_image/user/50609461_60x60.png'}, ‘reply_count’: 0}

In the 2 cases the comment doesn't appears on the website…
I'll look into it, maybe the reply_comment function doesn't work anymore

Last edited by TimMcCool (Sept. 13, 2022 21:24:04)


My profile / Mein Profil: @TimMcCool
JloAu
Scratcher
18 posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

TimMcCool wrote:

I'll look into it, maybe the reply_comment function doesn't work anymore

Thanks for replying! Here are some information that may help you…

1) I tried to reply with user.post_comment(“comment content”, parent_id=“id of the comment to reply to”, commentee_id=“”) but it didn't work…

2) I can “reply” using user.post_comment(f“@{name of the user to reply to} comment content”, parent_id=“”, commentee_id=“”). The message will not appear as a reply (below the original comment), but the user is mentioned in it and will be notified

Btw: I looked at the source code… I didn't think it was that big! I vaguely understood which parts made which requests to the Scratch servers. Congratulations again, this is the most competent python API for Scratch that I know of!

JloAu
My most famous project : ScratchOS
And my best project : ScratchOS 3.0
Learning to use ScratchAttach
ZZC12345
Scratcher
500+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

(removed)

Last edited by ZZC12345 (Sept. 14, 2022 07:50:25)


This is my signature. Contrary to popular belief, you do not need scratchblocks to protect against evil kumquats.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Make sure to check out these cool projects, written in real code!
Aviate - Itinerary - Scratch Auth - Orange OS Linux Distro - ocular - Leopard - PyHelp
NashwanYT
Scratcher
100+ posts

scratchattach - A Scratch API wrapper | v1.0 released (Python)

Is there any video tutorials on this package?


I use Pycharm has inbuilt pip and terminal

Last edited by NashwanYT (Sept. 16, 2022 14:11:45)

Powered by DjangoBB

Standard | Mobile