Discuss Scratch

DifferentDance8
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

jyotirmoy2020 wrote:

The code you have given here perfectly works!
Like I just proved…
TimMcCool
Scratcher
100+ posts

scratchclient - A scratch API wrapper for python

AdamKRPS425 wrote:

AdamKRPS425 wrote:

DifferentDance8 wrote:

AdamKRPS425 wrote:

AdamKRPS425 wrote:

im having trouble with editing cloud variables in my project, I don't get an error and the script keeps running but the variable does not change on Scratch

it's in my account, the project is shared and I'm logged in on the API (ScratchSession(“admkrps425”, “ThisIsToatalyMyRealPasswordNoCap”)) and I don't know what to do.

any help please


thanks in advance
hang on, does does the cloud variable need to start with the ☁ symbol?
i do not think so.
what could be the problem then?

I made a new script as a test and it gets stuck connecting to the project
this is the script
print("init")
from scratchclient import ScratchSession
print("logging on...")
session = ScratchSession("adamkrps425", "<placeholderpassword>")
print("connecting to project...")
connection = session.create_cloud_connection(726701801)
print("setting var...")
connection.set_cloud_variable("cloudVar", 1234)
print("done!")

and this is the console output

init
logging on…
connecting to project…
(still running as the posting of this btw its been like 5 min)


and as you see the cloud var on the project is still 0

Are you running the code on replit? Then it won't work. Scratch blocked replit from sending login request.

To set cloud variables with replit, you have to use cookie connect. I'm not sure if scratchclient has that feature, I couldn't find it in the documentation
TimMcCool
Scratcher
100+ posts

scratchclient - A scratch API wrapper for python

SomeoneOnThelnternet wrote:

mrcoat wrote:

SomeoneOnThelnternet wrote:

(#563)
Is it possible to add a session without my username and password? I want to use this to make a program but I don't want my password and stuff out there for anyone to see.
Depending on what you want to do, if you just want to see user/project stats then you just use scratch's api. But there isn't really a way to comment and interact with the website without using your password.
Ok, I just mainly want to see user followers and project stats and whatnot. How do I use the API?

i've never used scratchclient before now lol

To get your user / project stats, use @DatOneLefty's ScratchDB API:
https://scratchdb.lefty.one/v3/docs/#api-User-GetUserInfo

Example: (this will fetch your user stats)
import requests
stats = requests.get("https://scratchdb.lefty.one/v3/user/info/SomeoneOnThelnternet").json()

You can also get your user stats with scratchattach (doesn't require logging in) or scratchconnect:
import scratchattach as scratch3
user = scratch3.get_user("SomeoneOnTheInternet")
stats = user.stats()

Last edited by TimMcCool (Aug. 31, 2022 10:45:49)

DifferentDance8
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

I just made a script that follows and unfollows the account you choose to follow or unfollow.

from scratchclient import ScratchSession
username2 = input("Username? ")
password2 = input("Password? ")
session = ScratchSession(username2, password2)
follow_or_unfollow = input("Do you want to follow a user or unfollow a user? (\"y\" to follow, CASE SENSITIVE)")
if follow_or_unfollow == "y":
    print("Follow option selected!")
else:
    print("Unfollow option selected")
print("Enter in a user name")
user1 = input()
if follow_or_unfollow == "y":
    print(f"Following user {user1}...")
    session.get_user(user1).follow()
    print(f"User {user1} followed! Check your followers page! https://scratch.mit.edu/users/{username2}/following/")
    print("To follow or unfollow another user, run this script again!")
else:
    print(f"Unfollowing user {user1}")
    session.get_user(user1).unfollow()
    print(f"User {user1} followed! Check your followers page! https://scratch.mit.edu/users/{username2}/following/")
    print("To unfollow or follow another user, run this script again!")

So, if you wanted to follow gdpr0000001 using this script, you can!
Peterlll
Scratcher
11 posts

scratchclient - A scratch API wrapper for python

Are you guys really sure this can be used without risking a ban?
DifferentDance8
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

Peterlll wrote:

Are you guys really sure this can be used without risking a ban?
About as safe as using any other scratch python library!
ZZC12345
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

Peterlll wrote:

Are you guys really sure this can be used without risking a ban?
Yes. There are so many cloud projects using this and similar libraries out there, and they're all still up.
god286
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

Peterlll wrote:

(#587)
Are you guys really sure this can be used without risking a ban?
If you use social actions, like following, loving/favouriting, commenting, etc. then that is not allowed and you may be warned/banned.
Other than that, for just getting data and cloud variables, it should be safe.
DifferentDance8
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

god286 wrote:

Peterlll wrote:

(#587)
Are you guys really sure this can be used without risking a ban?
If you use social actions, like following, loving/favouriting, commenting, etc. then that is not allowed and you may be warned/banned.
…oh boy, time to edit my post to remove the script!
AdamKRPS425
Scratcher
44 posts

scratchclient - A scratch API wrapper for python

DifferentDance8 wrote:

AdamKRPS425 wrote:

really I would appreciate any help
Do you get a “scratchclient.ScratchExceptions.UnauthorizedException” error (meaning a 403, and I looked through the code), or a “scratchclient.ScratchExceptions.InvalidCredentialsException” error (meaning, well, your credentials are incorrect)?
I get this when posting the comment


and when changing a cloud variable the project just hangs, the console stays responsive but nothing happens. through testing I figured it got stuck on
connection = session.create_cloud_connection(726701801)
AdamKRPS425
Scratcher
44 posts

scratchclient - A scratch API wrapper for python

TimMcCool wrote:

AdamKRPS425 wrote:

AdamKRPS425 wrote:

DifferentDance8 wrote:

AdamKRPS425 wrote:

AdamKRPS425 wrote:

im having trouble with editing cloud variables in my project, I don't get an error and the script keeps running but the variable does not change on Scratch

it's in my account, the project is shared and I'm logged in on the API (ScratchSession(“admkrps425”, “ThisIsToatalyMyRealPasswordNoCap”)) and I don't know what to do.

any help please


thanks in advance
hang on, does does the cloud variable need to start with the ☁ symbol?
i do not think so.
what could be the problem then?

I made a new script as a test and it gets stuck connecting to the project
this is the script
print("init")
from scratchclient import ScratchSession
print("logging on...")
session = ScratchSession("adamkrps425", "<placeholderpassword>")
print("connecting to project...")
connection = session.create_cloud_connection(726701801)
print("setting var...")
connection.set_cloud_variable("cloudVar", 1234)
print("done!")

and this is the console output

init
logging on…
connecting to project…
(still running as the posting of this btw its been like 5 min)


and as you see the cloud var on the project is still 0

Are you running the code on replit? Then it won't work. Scratch blocked replit from sending login request.

To set cloud variables with replit, you have to use cookie connect. I'm not sure if scratchclient has that feature, I couldn't find it in the documentation
nope, running it locally
AdamKRPS425
Scratcher
44 posts

scratchclient - A scratch API wrapper for python

jyotirmoy2020 wrote:

AdamKRPS425 wrote:

AdamKRPS425 wrote:

DifferentDance8 wrote:

AdamKRPS425 wrote:

AdamKRPS425 wrote:

im having trouble with editing cloud variables in my project, I don't get an error and the script keeps running but the variable does not change on Scratch

it's in my account, the project is shared and I'm logged in on the API (ScratchSession(“admkrps425”, “ThisIsToatalyMyRealPasswordNoCap”)) and I don't know what to do.

any help please


thanks in advance
hang on, does does the cloud variable need to start with the ☁ symbol?
i do not think so.
what could be the problem then?

I made a new script as a test and it gets stuck connecting to the project
this is the script
print("init")
from scratchclient import ScratchSession
print("logging on...")
session = ScratchSession("adamkrps425", "<placeholderpassword>")
print("connecting to project...")
connection = session.create_cloud_connection(726701801)
print("setting var...")
connection.set_cloud_variable("cloudVar", 1234)
print("done!")

and this is the console output

init
logging on…
connecting to project…
(still running as the posting of this btw its been like 5 min)


and as you see the cloud var on the project is still 0


The code you have given here perfectly works!
does anyone have an idea as why it does not work for me? do I have to install something beside scrstchcliant? I run it in vs code do I need to run it directly in python? how long should it take?
ZZC12345
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

AdamKRPS425 wrote:

jyotirmoy2020 wrote:

~snip~
The code you have given here perfectly works!
does anyone have an idea as why it does not work for me? do I have to install something beside scrstchcliant? I run it in vs code do I need to run it directly in python? how long should it take?
What's the error?
DifferentDance8
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

ZZC12345 wrote:

AdamKRPS425 wrote:

jyotirmoy2020 wrote:

~snip~
The code you have given here perfectly works!
does anyone have an idea as why it does not work for me? do I have to install something beside scrstchcliant? I run it in vs code do I need to run it directly in python? how long should it take?
What's the error?

AdamKRPS425 wrote:

I get this when posting the comment
ZZC12345
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

DifferentDance8 wrote:

ZZC12345 wrote:

AdamKRPS425 wrote:

jyotirmoy2020 wrote:

~snip~
The code you have given here perfectly works!
does anyone have an idea as why it does not work for me? do I have to install something beside scrstchcliant? I run it in vs code do I need to run it directly in python? how long should it take?
What's the error?

AdamKRPS425 wrote:

I get this when posting the comment
Sorry!
Scratch returned a 403 error when you tried to post that comment. I'm not sure why.
https://github.com/CubeyTheCube/scratchclient/blob/cbabc79bbdeec1064e8de1c88480efdaebd5e1e7/scratchclient/User.py#L102-L103
NashwanYT
Scratcher
100+ posts

scratchclient - A scratch API wrapper for python

can u use pycharm it has inbuilt terminal and pip
DifferentDance8
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

NashwanYT wrote:

can u use pycharm it has inbuilt terminal and pip
Most of us would rather not pay 89 dollars USA for a product that can easily be replicated for 0 dollars USA with VSCode and a VSCode extension. Your choice, though.
Chiroyce
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

DifferentDance8 wrote:

NashwanYT wrote:

can u use pycharm it has inbuilt terminal and pip
Most of us would rather not pay 89 dollars USA for a product that can easily be replicated for 0 dollars USA with VSCode and a VSCode extension. Your choice, though.
Bruh PyCharm is free https://www.jetbrains.com/pycharm/download/ — secondly if they already have the paid version then what is wrong with using PyCharm for this? PyCharm is designed for Python

I've seen this as a trend with your posts, just take this as advise and maybe look through sources a bit more when you post

Last edited by Chiroyce (Sept. 17, 2022 05:09:55)

ZZC12345
Scratcher
500+ posts

scratchclient - A scratch API wrapper for python

DifferentDance8 wrote:

NashwanYT wrote:

can u use pycharm it has inbuilt terminal and pip
Most of us would rather not pay 89 dollars USA for a product that can easily be replicated for 0 dollars USA with VSCode and a VSCode extension. Your choice, though.
Most of the JetBrains IDEs are expensive if you pay for the commercial versions, but the community versions are free. The community ones are even open source! Next time, do some research before you post.

PyCharm Downloads wrote:

Download PyCharm

Professional
For both Scientific and Web Python development. With HTML, JS, and SQL support.
( Download )
Free 30-day trial available

Community
For pure Python development
( Download )
Free, built on open-source
The regular version is free.
DifferentDance8
Scratcher
1000+ posts

scratchclient - A scratch API wrapper for python

ZZC12345 wrote:

Most of the JetBrains IDEs are expensive if you pay for the commercial versions, but the community versions are free. The community ones are even open source! Next time, do some research before you post.
I know that. It's just that if you want to get support from JetBrains themselves, then you gotta pay up.

Powered by DjangoBB