Giter Site home page Giter Site logo

timmccool / scratchattach Goto Github PK

View Code? Open in Web Editor NEW
162.0 21.0 39.0 3.96 MB

Scratch API wrapper with support for almost all site features and cloud requests framework

License: MIT License

Python 100.00%
api bot bot-framework bots cloud python scratch

scratchattach's People

Contributors

eitan222 avatar engineerrunner avatar ententapl avatar grigoryshink avatar grisshink avatar jamesmedley avatar lizard-official avatar madu59 avatar namtacs avatar noverd avatar p-nutsk avatar quantum-codes avatar rc9910-scratch avatar redstone-dev avatar the-cloud-dev avatar thecommcraft avatar timmccool avatar yuwex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scratchattach's Issues

the project.update again

did project.update(likes) bc when i press l in the () it shows likes so it should be a thing and i got

image

Add a license

May I suggest that you add a license file to your repository? This determines what copyright license your work is using/licensed under and is what gives users permissions to work with (modify, share, use) the software. This will make collaboration easier and make it more clear what others can do with the software.

Just pointing that out in case this is an oversight.

I'd recommend checking out choosealicense.com to guide you on which license to use.

Thanks!

Login issue

so, while trying to log in to my account in scratchattach, it firstly returns with:
Failed to login. Either the provided authentication data is wrong or your network is banned from Scratch
The authentication data is correct, and i did login with the same account on the same network after that.
Then this long error message comes:

Traceback (most recent call last):
  File "/home/runner/mmo-crasher/venv/lib/python3.8/site-packages/scratchattach/_session.py", line 240, in login
    session_id = str(re.search('"(.*)"', request.headers["Set-Cookie"]).group())
AttributeError: 'NoneType' object has no attribute 'group'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    session = scratch3.login("", "")
  File "/home/runner/mmo-crasher/venv/lib/python3.8/site-packages/scratchattach/_session.py", line 243, in login
    raise(_exceptions.LoginFailure)
scratchattach._exceptions.LoginFailure

also, the same code worked about an hour earlier
i'm using replit btw

Edit: Removed login data - TimMcCool

Project Connect Error

I'm getting this error: Traceback (most recent call last): File "d:\Python\Scratch Cloud Requests\main.py", line 6, in <module> conn = session.connect_cloud(813916919) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: Session.connect_cloud() takes 1 positional argument but 2 were given

And here's my code: `import scratchattach as scratch3

session_id = "**************************************************"
session = scratch3.Session(session_id, username="CodeSoft_Games") #replace with your session_id and username
conn = session.connect_cloud(813916919)

client = scratch3.CloudRequests(conn)

@client.request
def ping(): #called when client receives request
print("Ping request received")
return "pong" #sends back 'pong' to the Scratch project

@client.event
def on_ready():
print("Request handler is running")
client.run() #make sure this is ALWAYS at the bottom of your Python file`

'NoneType' object has no attribute '_username'

File "c:\Users\scrat\Desktop\ahahahh.py", line 8, in
project.love()
File "C:\Users\scrat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\scratchattach_project.py", line 216, in love
f"https://api.scratch.mit.edu/proxy/projects/{self.id}/loves/user/{self._session._username}",
AttributeError: 'NoneType' object has no attribute '_username'

this is the code:
projectnum = randint(0,600000000)
project = scratch3.get_project(f"{projectnum}")
project.love()

To many requests

i did

while True:
Ping = Project.get_var("Ping")
print(Ping)
if Ping == 1:
print("Pong")
City_Requested = Project.get_var("City")
Units = Project.get_var("Unit")
Decode(City_Requested)
GeoCode(Decoded)
Decode(Units)
Get_Temperature(Latitude,Longitude, Decoded)
Project.set_var("Temperature", round(Temperature))
Project.set_var("Ping", 0)

time.sleep(10)

there is like 50 other lines of code but this is all that actualy interacts with the project
no errors but it is not working also when go scratch3.get_health() it says to many requests
here is replit link https://replit.com/@CodeKid11/ScratchAttach-Weather

Not setting cloud variables.

My script runs fine and everything seems normal but it does not actually update the variable when looking at the logs. I have tried this on multiple different computers with different scratch acounts.
import scratchattach as scratch3
session = scratch3.login("username", "password")
conn = session.connect_cloud("projectid")
conn.set_var("variable", "value")
conn.disconnect()
I know scratch has been changing how their api works so idk if thats affecting it. I can still pull values though.

How to send a dictionary?

I need to send a .txt file, which was converted into a dictionary, which I need to send it all. What do I do? No, I cannot use commas because my text lines use commas.

Number of arguments is 1 above needed

session = scratch.Session(my_secret, "MadAsTK")
TypeError: init() takes 2 positional arguments but 3 were given

I'm using replit, so my_secret is my session btw
I tried this with VS Code and got the same error

Installing issue

When using pip install scratchattach I get an error message saying "'pip' is not recognized as an internal or external command,
operable program or batch file." This is for using command prompt, shell, and python.

Please reply here, or if urgent at [email protected] OR [email protected].

(This issue was also put on Tims scratch page.)

it wont let me login

when i put the thing it says 'session' is not recognized as an internal or external command,
operable program or batch file.

Forgot "project.title"

Hey Tim You Forgot the "project.title" function in the projects area

Attributes:

project.id #Returns the project id
project.url #Returns the project url

project.title #Returns the project title<<<<<<< This is that you forgot

project.author #Returns the username of the author
project.comments_allowed #Returns True if comments are enabled
project.instructions
project.notes #Returns the 'Notes and Credits' section
project.created #Returns the date of the project creation
project.last_modified #Returns the date when the project was modified the last time
project.share_date
project.thumbnail_url
project.remix_parent
project.remix_root
project.loves #Returns the love count
project.favorites #Returns the project's favorite count
project.remix_count #Returns the number of remixes
project.views #Returns the view count
project.project_token

----- -----

project.update() #Updates the above data

Question about the downloading project function

https://github.com/TimMcCool/scratch3.py/blob/c01b80b8bd2eb900d7aa40b0d5f28a066b92c396/scratch3/_project.py#L39

When downloading a project from projects.scratch.mit.edu, it only returns the project's JSON file (example), and SB3 files are actually a zipped up version of all the assets and the JSON file, but when writing only the JSON content to the SB3 file, I'm not sure if it would be a valid. When I tried it out with the online editor it worked successfully since the assets are already stored on the server, I'm not sure if it will be valid when you try to load it with the offline editor though.

get_user() issue

Hi Tim, MadAsTK here. Been having problems with the get_user() function. Here's the error:

Traceback (most recent call last):
File "/home/runner/getusr/venv/lib/python3.8/site-packages/scratchattach/_user.py", line 50, in _update_from_dict
self.id = response["id"]
KeyError: 'id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "main.py", line 9, in
user = scratchattach.get_user("username")
File "/home/runner/getusr/venv/lib/python3.8/site-packages/scratchattach/_user.py", line 534, in get_user
user.update()
File "/home/runner/getusr/venv/lib/python3.8/site-packages/scratchattach/_user.py", line 45, in update
self._update_from_dict(response)
File "/home/runner/getusr/venv/lib/python3.8/site-packages/scratchattach/_user.py", line 53, in _update_from_dict
raise(_exceptions.UserNotFound)
scratchattach._exceptions.UserNotFound

It says UserNotFound, even though MadAsTK, what it put there, is a real username. Have a solution?

Frank Was Here

Code formatting still not ideal

Ever since #24 was closed, the code formatting on this project has been inconsistent. Running a formatter is not a one-and-done thing. It has to be repeatedly done as a chore. I suggest creating a pre-commit hook to format your code with black so the code is formatter as you commit.

Why does this happen?

Whenever you set a cloud variable once, then it will register in the cloud monitor, but, whenever the project loads, it's reset back to zero. Is there any way you can fix this? BTW, it still works if you repeatedly set the variables, but, as soon the program stops setting the variables, they are reset back to zero again.

AttributeError: 'User' object has no attribute 'about_me'

Basically I'm making a statistics project. I manually scraped 96,000 Scratch users. I'm trying to save all their data to a text file. But this function sometimes doesn't work, and says the error in the title.
def get_user_data(obj: scratch3.User): return str({"username": obj.username, "joinDate": obj.join_date, "aboutMe": obj.about_me, "workingOn": obj.wiwo, "followers": obj.follower_count(), "following": obj.following_count(), "projects": obj.project_count(), "favorites": obj.favorites_count(), "studios": obj.studio_count(), "usersFollowing": obj.following()})

IDEA: Detect if replit is being used, and use a proxy if so.

Basically what the title above says. I know that you can just use session id login, but that's a lot heftier of a process than a username and password.

  • Find a way to check for replit
  • Implement the way
  • Use a proxy for replit users
  • Check the proxy works
  • Confirm replit integration works

Error Decoding

When I run this replit sometimes I get this error. It says Line 63 which is just decoded = Encoding.decode(encoded)
the project is project and the repl is repl

The error is

Exception in thread Thread-3 (_update): Traceback (most recent call last): File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/threading.py", line 953, in run self._target(*self._args, **self._kwargs) File "/home/runner/Scratch-Coin/venv/lib/python3.10/site-packages/scratchattach/_cloud.py", line 232, in _update self._events["on_"+activity["verb"][:-4]](self.Event(user=activity["user"], var=activity["name"][2:], name=activity["name"][2:], value=activity["value"], timestamp=activity["timestamp"])) File "main.py", line 63, in on_set decoded = Encoding.decode(encoded) File "/home/runner/Scratch-Coin/venv/lib/python3.10/site-packages/scratchattach/_encoder.py", line 119, in decode letter = letters[int(f"{inp[i*2]}{inp[(i*2)+1]}")] ValueError: invalid literal for int() with base 10: 'No'

Edit: I check what the variable is set to before the error occurs and it is None which I assume is nonetype but the cloud variable is 0

Cloud Vars not working

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scratchattach/_cloud.py", line 71, in _connect
self.websocket.connect(
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websocket/_core.py", line 249, in connect
self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options),
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websocket/_http.py", line 136, in connect
sock = _ssl_socket(sock, options.sslopt, hostname)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websocket/_http.py", line 271, in _ssl_socket
sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websocket/_http.py", line 247, in _wrap_sni_socket
return context.wrap_socket(
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 517, in wrap_socket
return self.sslsocket_class._create(
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1075, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1346, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/hannah/Documents/Test.py", line 5, in
Connect = Session.connect_cloud("782892053")
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scratchattach/_session.py", line 247, in connect_cloud
return _cloud.CloudConnection(username = self._username, session_id = self.session_id, project_id = int(project_id))
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scratchattach/_cloud.py", line 22, in init
self._connect(cloud_host=cloud_host)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scratchattach/_cloud.py", line 78, in _connect
raise(_exceptions.ConnectionError)
scratchattach._exceptions.ConnectionError

An Error

I was working on this and I got this error

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    session = scratch3.Session(session)
  File "/home/runner/LoveToChangeTitle/venv/lib/python3.8/site-packages/scratch3/_session.py", line 31, in __init__
    self._get_xtoken()
  File "/home/runner/LoveToChangeTitle/venv/lib/python3.8/site-packages/scratch3/_session.py", line 43, in _get_xtoken
    response = json.loads(requests.post(
  File "/nix/store/p21fdyxqb3yqflpim7g8s1mymgpnqiv7-python3-3.8.12/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/nix/store/p21fdyxqb3yqflpim7g8s1mymgpnqiv7-python3-3.8.12/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/nix/store/p21fdyxqb3yqflpim7g8s1mymgpnqiv7-python3-3.8.12/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)
 




Cloud Requests bug when requsting a { with out the other }

I was testing this to see if this will work in my scratch os but when i try to add a { it bugs

PS C:\Users\Nathan> & C:/Python/python.exe c:/Users/User/Desktop/Stuff/cloudbreaker.py
If you use CloudRequests in your Scratch project, please credit TimMcCool!
Request handler is running
Caught error in request 'BugFinder' - Full error below
Traceback (most recent call last):
  File "C:\Python\lib\site-packages\scratchattach\_cloud_requests.py", line 61, in call_request
    output = req_obj["on_call"](*arguments)
TypeError: BugFinder() takes 1 positional argument but 2 were given

Unable to create session

For some reason, whenever I try to create a session, I get this error.
Traceback (most recent call last): File "C:\Users\chopr\OneDrive\Documents\coding\Python\scratchattach.py", line 1, in <module> import scratchattach as scratch3 File "C:\Users\chopr\OneDrive\Documents\coding\Python\scratchattach.py", line 2, in <module> session = scratch3.login("shivitests", "******") # blurred for github AttributeError: partially initialized module 'scratchattach' has no attribute 'login' (most likely due to a circular import)

Turbowarp error for AttributeError: 'TwCloudRequests' object has no attribute 'respond_in_thread'

I'm using repl, and it keeps coming up with that error for some reason.
Full error:
Traceback (most recent call last):
File "main.py", line 569, in
client.run()
File "/home/runner/TechnologicalLiveProcesses/venv/lib/python3.8/site-packages/scratchattach/_cloud_requests.py", line 334, in run
self._run(events, data_from_websocket=True)
File "/home/runner/TechnologicalLiveProcesses/venv/lib/python3.8/site-packages/scratchattach/_cloud_requests.py", line 295, in _run
self.call_request(request_id, req_obj, arguments)
File "/home/runner/TechnologicalLiveProcesses/venv/lib/python3.8/site-packages/scratchattach/_cloud_requests.py", line 55, in call_request
if not self.respond_in_thread:
AttributeError: 'TwCloudRequests' object has no attribute 'respond_in_thread'
(this was a test project)

i see

i see youve had months and still have not fixed the \ issue it sees it as e when i decode it

suggestion| can you add multiple returns?

like can you add return multiple things? like in the request block on scratch add a parameter called rets and the script only ends when i return the same number of returns in rets

Make a light mode Cloud Request Template?

Hola! I was wondering if you could make a light mode version of your Cloud Request Template? Because the CRT uses all 10 vars and so more cant be made could you make a light mode like using only 5 Cloud Vars? I know like your done with Scratchattach but maybe...?

sees variables as lists

it appears if i do this it sees the variable as a list. why?

while repeat == 1:
protocol_part = scratch3.get_var(“project”, “protocol”)
protocol = Encoding.decode(protocol_part)
if protocol == “h200”:
print(protocol)

How to set a cloud variable with CloudEvents

I've been searching on the wiki and on Scratch for a while but I have no clue how to set a variable with the CloudEvents thing. When looking into _requests.py I see you just did it manually... How am I supposed to do it ?

Scratchattach not working

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scratchattach/_cloud.py", line 71, in _connect
self.websocket.connect(
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websocket/_core.py", line 249, in connect
self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websocket/_http.py", line 136, in connect
sock = _ssl_socket(sock, options.sslopt, hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websocket/_http.py", line 271, in _ssl_socket
sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/websocket/_http.py", line 247, in _wrap_sni_socket
return context.wrap_socket(
^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 517, in wrap_socket
return self.sslsocket_class._create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1075, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1346, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/marklopezjr/mas6y6/Scratch_cloud/SCRATCH_CLOUD.py", line 81, in
conn = session.connect_cloud(project_id="737869642")#replace with your project id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scratchattach/_session.py", line 247, in connect_cloud
return _cloud.CloudConnection(username = self._username, session_id = self.session_id, project_id = int(project_id))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scratchattach/_cloud.py", line 22, in init
self._connect(cloud_host=cloud_host)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scratchattach/_cloud.py", line 78, in _connect
raise(_exceptions.ConnectionError)
scratchattach._exceptions.ConnectionError

when using User.follow() following "bob"

File "c:\Users\scrat\Desktop\follow.py", line 8, in
hi.follow()
File "C:\Users\scrat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\scratchattach_user.py", line 302, in follow
f"https://scratch.mit.edu/site-api/users/followers/bob/add/?usernames={self._session._username}",
AttributeError: 'NoneType' object has no attribute '_username'

I am confused. firstly, i am getting an error for no reason I can think of, and from the api call show in the error it looks as if I would just end up following "bob" instead, which has happened before

/

/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.