Discuss Scratch

Knightbot63
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

ajskateboarder wrote:

(#1646)

Knightbot63 wrote:

I am not sure if it's just me or the installation won't work.
https://assets.scratch.mit.edu/get_image/.%2E/390f3742f561c9cb9f3f9f9e3fec82ad.png
What on god's green earth happened to pip ☠
It may probably need updating. Same with Linux
ajskateboarder
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

Knightbot63 wrote:

ajskateboarder wrote:

(#1646)

Knightbot63 wrote:

I am not sure if it's just me or the installation won't work.
https://assets.scratch.mit.edu/get_image/.%2E/390f3742f561c9cb9f3f9f9e3fec82ad.png
What on god's green earth happened to pip ☠
It may probably need updating. Same with Linux
But that's Python 3.11, one of the latest versions. Confusing
You should probably use pipx or create a virtual environment, it's recommended anyways to avoid dependency conflicts:
$ python3 -m venv env
$ source env/bin/activate
$ pip install scratchattach
henry1cypher
Scratcher
77 posts

scratchattach - A Scratch API wrapper (Python)

TimMcCool wrote:

Scratch API wrapper with support for almost all site features. The library can set cloud variables, follow Scratchers, post comments and do so much more!

It has special features that make it easy to transmit data through cloud variables.

Available on PyPi and on GitHub: https://github.com/TimMcCool/scratchattach

Quick Documentation

(Full documentation) (Official studio for scratchattach projects)

Installation:

Run this command in your command prompt / shell:
pip install -U scratchattach

Features:

- Get and set cloud variables on any Scratch project

- Cloud events

- Cloud requests that allow Scratch projects and Python to interact

- Get and interact with users, projects and studios

- Get and interact with Forum Posts / Topics

… and much more!

Examples

Setting a cloud var with scratchattach:
import scratchattach as scratch3

session = scratch3.login("username", "password")
conn = session.connect_cloud("project_id")

conn.set_var("variable", value)
Cloud Requests:
Link to examples

Cloud event handler:
import scratchattach as scratch3
events = scratch3.CloudEvents("project_id")

@events.event
def on_set(event): #Called when a cloud var is set
print(f"{event.user} set the variable {event.var} to the valuee {event.value} at {event.timestamp}")

events.start()

(Full documentation) (Official studio for scratchattach projects)

Support and Bug Report

If you have a question, ask here or create an issue on the repo.

Reasons to use scratchattach

➥ Simple to use
➥ Fast and safe
➥ Cloud events & built-in class for encoded cloud requests
➥ Users, projects, comments, search, explore & more!
➥ Forum posts and topics
➥ Most features don't require a session
➥ Open-source



Note
This topic is for talking about scratchattach and reporting bugs / glitches, not for advertising projects or other libraries.
i don't understand it i tried to replit
Knightbot63
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

henry1cypher wrote:

(#1649)
i don't understand it i tried to replit
Scratch blocked replit's IP. Also, please don't quote the OP
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

ajskateboarder wrote:

wvzack wrote:

probully super simple but i cant find a way to use the “split()” (really i dont care if it uses split or something else as long as it works) to separate the value of user.comments(limit=1, page=1) into usable stuff like one var named “comment_id” and one named “comment_content” ect. ect..
instead of [{'CommentID': ‘265564665’, ‘User’: ‘__boat__’, ‘Content’: ‘/comment info’, ‘Timestamp’: ‘2023-04-26T01:39:56Z’, ‘hasReplies?’: True, ‘Replies’: }]
f8erhf4ervjfwbjfwurfwiesijbrufiehwiubiubfiubfbug4w848v It's called JSON
You should really go to PyHelp, you should never use str.split to parse JSON

Use json.loads, it's in the standard library:
import json
json_string = user.comments(limit=1, page=1)
# parse the text and get the first item (it's a list)
item = json.loads(json_string)[0]
# print the values of CommentID and Content using *bracket* notation
print(item["CommentID"], item["Content"])
it doesn't work because it needs to be:
import json
json_string = user.comments(limit=1, page=1)
item = json.loads(json_string)[0]
# print the values of CommentID and Content using *bracket* notation
print(item["CommentID"], item["Content"])

Last edited by wvzack (April 28, 2023 23:12:36)

Mast_Scratch
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

I need help… scratchattach is actually messing with me or it might be vscode…

When I run

from scratchattach import Encoding

it gives me

cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)
File “D:\Desktop\scratchattach\scratchattach.py”, line 4, in <module>
from scratchattach import Encoding
File “D:\Desktop\scratchattach\scratchattach.py”, line 3, in <module>
import scratchattach as s3
ImportError: cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)

BRUH
god286
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

Mast_Scratch wrote:

(#1652)
I need help… scratchattach is actually messing with me or it might be vscode…

When I run

from scratchattach import Encoding

it gives me

cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)
File “D:\Desktop\scratchattach\scratchattach.py”, line 4, in <module>
from scratchattach import Encoding
File “D:\Desktop\scratchattach\scratchattach.py”, line 3, in <module>
import scratchattach as s3
ImportError: cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)

BRUH
Your file can't be called scratchattach.py because Python thinks you are trying to import your file and not the scratchattach module. Change the file name to something else.
Mast_Scratch
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

god286 wrote:

Mast_Scratch wrote:

(#1652)
I need help… scratchattach is actually messing with me or it might be vscode…

When I run

from scratchattach import Encoding

it gives me

cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)
File “D:\Desktop\scratchattach\scratchattach.py”, line 4, in <module>
from scratchattach import Encoding
File “D:\Desktop\scratchattach\scratchattach.py”, line 3, in <module>
import scratchattach as s3
ImportError: cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)

BRUH
Your file can't be called scratchattach.py because Python thinks you are trying to import your file and not the scratchattach module. Change the file name to something else.

oh right I forgot… thank you!

P.S. That was quick

Double P.S. Now I get the error Exception has occurred: ModuleNotFoundError
No module named ‘scratchattach’
File “D:\Desktop\scratchattach\messenger.py”, line 3, in <module>
import scratchattach as s3
ModuleNotFoundError: No module named ‘scratchattach’

I did install scratchattach

Last edited by Mast_Scratch (April 29, 2023 07:21:06)

-FreeEngines-
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

Mast_Scratch wrote:

god286 wrote:

Mast_Scratch wrote:

(#1652)
I need help… scratchattach is actually messing with me or it might be vscode…

When I run

from scratchattach import Encoding

it gives me

cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)
File “D:\Desktop\scratchattach\scratchattach.py”, line 4, in <module>
from scratchattach import Encoding
File “D:\Desktop\scratchattach\scratchattach.py”, line 3, in <module>
import scratchattach as s3
ImportError: cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)

BRUH
Your file can't be called scratchattach.py because Python thinks you are trying to import your file and not the scratchattach module. Change the file name to something else.

oh right I forgot… thank you!

P.S. That was quick

Double P.S. Now I get the error Exception has occurred: ModuleNotFoundError
No module named ‘scratchattach’
File “D:\Desktop\scratchattach\messenger.py”, line 3, in <module>
import scratchattach as s3
ModuleNotFoundError: No module named ‘scratchattach’

I did install scratchattach
how did you attempt to install it? also why are you importing it as s3? / is the messenger.py an interal scratchattach file? if yes, why is it on your deskropt
Mast_Scratch
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

-FreeEngines- wrote:

Mast_Scratch wrote:

god286 wrote:

Mast_Scratch wrote:

(#1652)
I need help… scratchattach is actually messing with me or it might be vscode…

When I run

from scratchattach import Encoding

it gives me

cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)
File “D:\Desktop\scratchattach\scratchattach.py”, line 4, in <module>
from scratchattach import Encoding
File “D:\Desktop\scratchattach\scratchattach.py”, line 3, in <module>
import scratchattach as s3
ImportError: cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)

BRUH
Your file can't be called scratchattach.py because Python thinks you are trying to import your file and not the scratchattach module. Change the file name to something else.

oh right I forgot… thank you!

P.S. That was quick

Double P.S. Now I get the error Exception has occurred: ModuleNotFoundError
No module named ‘scratchattach’
File “D:\Desktop\scratchattach\messenger.py”, line 3, in <module>
import scratchattach as s3
ModuleNotFoundError: No module named ‘scratchattach’

I did install scratchattach
how did you attempt to install it? also why are you importing it as s3? / is the messenger.py an interal scratchattach file? if yes, why is it on your deskropt

wow, I installed it with pip, I am importing it as s3 cuz it is easy to code that way, what do you mean an internal scratchattach file? I have it on my desktop because I want quick access to it. Why did you needed that answer anyways…
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

So this is my code

import scratchattach as scratch3
import os
import time
import json
session = scratch3.login("wvzacktest", "************************")
user = session.connect_user("wvzack")
newestcomment = user.comments(limit=1, page=1)[0]['Content']
comment_info = user.comments(limit=1, page=1)
import json
json_string = comment_info
item = json.loads(json_string)[0]
print(item["CommentID"], item["Content"])
print(data[User])

and i get

Exception has occurred: TypeError
the JSON object must be str, bytes or bytearray, not list
File "C:\Users\*******\.vscode\code1.py", line 14, in <module>
item = json.loads(json_string)[0]
^^^^^^^^^^^^^^^^^^^^^^^
TypeError: the JSON object must be str, bytes or bytearray, not list
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

wvzack wrote:

So this is my code

import scratchattach as scratch3
import os
import time
import json
session = scratch3.login("wvzacktest", "************************")
user = session.connect_user("wvzack")
newestcomment = user.comments(limit=1, page=1)[0]['Content']
comment_info = user.comments(limit=1, page=1)
import json
json_string = comment_info
item = json.loads(json_string)[0]
print(item["CommentID"], item["Content"])
print(data[User])

and i get

Exception has occurred: TypeError
the JSON object must be str, bytes or bytearray, not list
File "C:\Users\*******\.vscode\code1.py", line 14, in <module>
item = json.loads(json_string)[0]
^^^^^^^^^^^^^^^^^^^^^^^
TypeError: the JSON object must be str, bytes or bytearray, not list

the comment_info is equal to
[{u'Timestamp': u'2023-04-28T22:41:23Z', u'Content': u"[{u'Timestamp': u'2023-04-28T22:40:19Z', u'Content': u'Hahahahahhahahahaha /comment_info', u'User': u'Games-m', u'Replies': [], u'CommentID': u'266096065', u'hasReplies?': False}]", u'User': u'wvzacktest', u'Replies': [], u'CommentID': u'266096236', u'hasReplies?': False}]

Edit: i fixed it

Last edited by wvzack (April 29, 2023 17:28:51)

maDU59_
Scratcher
60 posts

scratchattach - A Scratch API wrapper (Python)

Mast_Scratch wrote:

-FreeEngines- wrote:

Mast_Scratch wrote:

god286 wrote:

Mast_Scratch wrote:

(#1652)
I need help… scratchattach is actually messing with me or it might be vscode…

When I run

from scratchattach import Encoding

it gives me

cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)
File “D:\Desktop\scratchattach\scratchattach.py”, line 4, in <module>
from scratchattach import Encoding
File “D:\Desktop\scratchattach\scratchattach.py”, line 3, in <module>
import scratchattach as s3
ImportError: cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)

BRUH
Your file can't be called scratchattach.py because Python thinks you are trying to import your file and not the scratchattach module. Change the file name to something else.

oh right I forgot… thank you!

P.S. That was quick

Double P.S. Now I get the error Exception has occurred: ModuleNotFoundError
No module named ‘scratchattach’
File “D:\Desktop\scratchattach\messenger.py”, line 3, in <module>
import scratchattach as s3
ModuleNotFoundError: No module named ‘scratchattach’

I did install scratchattach
how did you attempt to install it? also why are you importing it as s3? / is the messenger.py an interal scratchattach file? if yes, why is it on your deskropt

wow, I installed it with pip, I am importing it as s3 cuz it is easy to code that way, what do you mean an internal scratchattach file? I have it on my desktop because I want quick access to it. Why did you needed that answer anyways…

Your python script is located in a “scratchattach” folder, I think you should try renaming that folder
D:\Desktop\scratchattach\messenger.py
BluShuMon
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

How do you print the data you get from the response?
MonkeyBean2
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

BluShuMon wrote:

How do you print the data you get from the response?
print(the_data_you_got_from_the_response)

Last edited by MonkeyBean2 (April 29, 2023 19:47:34)

ajskateboarder
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

BluShuMon wrote:

How do you print the data you get from the response?
print(variable)
Where variable is the name of the variable you assigned your data to

Python tutorial
Thekidlaroi165
Scratcher
10 posts

scratchattach - A Scratch API wrapper (Python)

TimMcCool wrote:

Scratch API wrapper with support for almost all site features. The library can set cloud variables, follow Scratchers, post comments and do so much more!

It has special features that make it easy to transmit data through cloud variables.

Available on PyPi and on GitHub: https://github.com/TimMcCool/scratchattach

Quick Documentation

(Full documentation) (Official studio for scratchattach projects)

Installation:

Run this command in your command prompt / shell:
pip install -U scratchattach

Features:

- Get and set cloud variables on any Scratch project

- Cloud events

- Cloud requests that allow Scratch projects and Python to interact

- Get and interact with users, projects and studios

- Get and interact with Forum Posts / Topics

… and much more!

Examples

Setting a cloud var with scratchattach:
import scratchattach as scratch3

session = scratch3.login("username", "password")
conn = session.connect_cloud("project_id")

conn.set_var("variable", value)
Cloud Requests:
Link to examples

Cloud event handler:
import scratchattach as scratch3
events = scratch3.CloudEvents("project_id")

@events.event
def on_set(event): #Called when a cloud var is set
print(f"{event.user} set the variable {event.var} to the valuee {event.value} at {event.timestamp}")

events.start()

(Full documentation) (Official studio for scratchattach projects)

Support and Bug Report

If you have a question, ask here or create an issue on the repo.

Reasons to use scratchattach

➥ Simple to use
➥ Fast and safe
➥ Cloud events & built-in class for encoded cloud requests
➥ Users, projects, comments, search, explore & more!
➥ Forum posts and topics
➥ Most features don't require a session
➥ Open-source



Note
This topic is for talking about scratchattach and reporting bugs / glitches, not for advertising projects or other libraries.
I tried to run the commands but it says “SyntaxError”
GIitchInTheMatrix
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

Thekidlaroi165 wrote:

I tried to run the commands but it says “SyntaxError”
Whats the code you tried? Be sure not to include your password.
ajskateboarder
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

Thekidlaroi165 wrote:

I tried to run the commands but it says “SyntaxError”
Please don't quote the entire OP and paste your code here inside a [code][/code] tag
Mast_Scratch
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

maDU59_ wrote:

Mast_Scratch wrote:

-FreeEngines- wrote:

Mast_Scratch wrote:

god286 wrote:

Mast_Scratch wrote:

(#1652)
I need help… scratchattach is actually messing with me or it might be vscode…

When I run

from scratchattach import Encoding

it gives me

cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)
File “D:\Desktop\scratchattach\scratchattach.py”, line 4, in <module>
from scratchattach import Encoding
File “D:\Desktop\scratchattach\scratchattach.py”, line 3, in <module>
import scratchattach as s3
ImportError: cannot import name ‘Encoding’ from partially initialized module ‘scratchattach’ (most likely due to a circular import) (D:\Desktop\scratchattach\scratchattach.py)

BRUH
Your file can't be called scratchattach.py because Python thinks you are trying to import your file and not the scratchattach module. Change the file name to something else.

oh right I forgot… thank you!

P.S. That was quick

Double P.S. Now I get the error Exception has occurred: ModuleNotFoundError
No module named ‘scratchattach’
File “D:\Desktop\scratchattach\messenger.py”, line 3, in <module>
import scratchattach as s3
ModuleNotFoundError: No module named ‘scratchattach’

I did install scratchattach
how did you attempt to install it? also why are you importing it as s3? / is the messenger.py an interal scratchattach file? if yes, why is it on your deskropt

wow, I installed it with pip, I am importing it as s3 cuz it is easy to code that way, what do you mean an internal scratchattach file? I have it on my desktop because I want quick access to it. Why did you needed that answer anyways…

Your python script is located in a “scratchattach” folder, I think you should try renaming that folder
D:\Desktop\scratchattach\messenger.py

Wait I need to rename that folder? ok doing it

Powered by DjangoBB