Skip to content

Commit 008c5d6

Browse files
committed
docs: use copy of sawiki instead of reference
1 parent 268e549 commit 008c5d6

13 files changed

+272
-1
lines changed

docs/SA-Wiki/Cloud-Requests.md

Whitespace-only changes.

docs/SA-Wiki/Cloud-Storage.md

Whitespace-only changes.

docs/SA-Wiki/Documentation.md

Whitespace-only changes.

docs/SA-Wiki/Examples.md

Whitespace-only changes.

docs/SA-Wiki/Filterbot.md

Whitespace-only changes.

docs/SA-Wiki/Get-your-session-id.md

Whitespace-only changes.

docs/SA-Wiki/Home.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
**Scratch API wrapper with support for almost all site features.** Created by [TimMcCool](https://scratch.mit.edu/users/TimMcCool/).
2+
3+
This 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.
4+
5+
<p align="left">
6+
<img width="120" src="https://github.com/TimMcCool/scratchattach/blob/main/logos/logo.svg">
7+
</p>
8+
9+
[![PyPI status](https://img.shields.io/pypi/status/scratchattach.svg)](https://pypi.python.org/pypi/scratchattach/)
10+
[![PyPI download month](https://img.shields.io/pypi/dm/scratchattach.svg)](https://pypi.python.org/pypi/scratchattach/)
11+
[![PyPI version shields.io](https://img.shields.io/pypi/v/scratchattach.svg)](https://pypi.python.org/pypi/scratchattach/)
12+
[![GitHub license](https://badgen.net/github/license/TimMcCool/scratchattach)](https://github.com/TimMcCool/scratchattach/blob/master/LICENSE)
13+
[![Documentation Status](https://readthedocs.org/projects/scratchattach/badge/?version=latest)](https://scratchattach.readthedocs.io/en/latest/?badge=latest)
14+
15+
## It is *strongly* advised to learn Python before using scratchattach.
16+
17+
# Documentation
18+
19+
- **[Documentation](https://github.com/TimMcCool/scratchattach/wiki/Documentation)**
20+
21+
- [Cloud Variables](https://github.com/TimMcCool/scratchattach/wiki/Documentation#cloud-variables)
22+
- [Cloud Requests](https://github.com/TimMcCool/scratchattach/wiki/Cloud-Requests)
23+
- [Cloud Storage](https://github.com/TimMcCool/scratchattach/wiki/Cloud-Storage)
24+
- [Filterbot](https://github.com/TimMcCool/scratchattach/wiki/Filterbot)
25+
- [Self-hosting a TW cloud websocket](https://github.com/TimMcCool/scratchattach/wiki/Documentation#hosting-a-cloud-server)
26+
27+
# Helpful resources
28+
29+
- [Get your session id](https://github.com/TimMcCool/scratchattach/wiki/Get-your-session-id)
30+
31+
- [Examples](https://github.com/TimMcCool/scratchattach/wiki/Examples)
32+
- [Hosting](https://github.com/TimMcCool/scratchattach/wiki/Hosting)
33+
34+
- [Migrating to v2](https://github.com/TimMcCool/scratchattach/wiki/Migrating-to-v2)
35+
36+
Report bugs by opening an issue on this repository. If you need help or guideance, leave a comment in the [official forum topic](https://scratch.mit.edu/discuss/topic/603418/
37+
). Projects made using scratchattach can be added to [this Scratch studio](https://scratch.mit.edu/studios/31478892/).
38+
39+
# Helpful for contributors
40+
41+
- **[Structure of the library](https://github.com/TimMcCool/scratchattach/wiki/Structure-of-the-library)**
42+
43+
- [Extended documentation (WIP)](https://scratchattach.readthedocs.io/en/latest/)
44+
45+
- [Change log](https://github.com/TimMcCool/scratchattach/blob/main/CHANGELOG.md)
46+
47+
Contribute code by opening a pull request on this repository.
48+
49+
# ️Example usage
50+
51+
Set a cloud variable:
52+
53+
```py
54+
import scratchattach as sa
55+
56+
session = sa.login("username", "password")
57+
cloud = session.connect_cloud("project_id")
58+
59+
cloud.set_var("variable", value)
60+
```
61+
62+
**[More examples](https://github.com/TimMcCool/scratchattach/wiki/Examples)**
63+
64+
# Getting started
65+
66+
**Installation:**
67+
68+
Run the following command in your command prompt / shell:
69+
70+
```
71+
pip install -U scratchattach
72+
```
73+
74+
If this doesn't work, try running:
75+
```
76+
python -m pip install -U scratchattach
77+
```
78+
79+
80+
**Logging in with username / password:**
81+
82+
```python
83+
import scratchattach as sa
84+
85+
session = sa.login("username", "password")
86+
```
87+
88+
`login()` returns a `Session` object that saves your login and can be used to connect objects like users, projects, clouds etc.
89+
90+
**Logging in with a sessionId:** *You can get your session id from your browser's cookies. [More information](https://github.com/TimMcCool/scratchattach/wiki/Get-your-session-id)*
91+
```python
92+
import scratchattach as sa
93+
94+
session = sa.login_by_id("sessionId", username="username") #The username field is case sensitive
95+
```
96+
97+
**Cloud variables:**
98+
99+
```py
100+
cloud = session.connect_cloud("project_id") # connect to the cloud
101+
102+
value = cloud.get_var("variable")
103+
cloud.set_var("variable", "value") # the variable name is specified without the cloud emoji
104+
```
105+
106+
**Cloud events:**
107+
108+
```py
109+
cloud = session.connect_cloud('project_id')
110+
events = cloud.events()
111+
112+
@events.event
113+
def on_set(activity):
114+
print("variable", activity.var, "was set to", activity.value)
115+
events.start()
116+
```
117+
118+
**Follow users, love their projects and comment:**
119+
120+
```py
121+
user = session.connect_user('username')
122+
user.follow()
123+
124+
project = user.projects()[0]
125+
project.love()
126+
project.post_comment('Great project!')
127+
```
128+
129+
**All scratchattach features are documented in the [documentation](https://github.com/TimMcCool/scratchattach/wiki/Documentation).**

docs/SA-Wiki/Hosting.md

Whitespace-only changes.

docs/SA-Wiki/Migrating-to-v2.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Scratchattach v2 is not backwards compatible. But upgrading is worth it, because it comes with many new features.
2+
3+
This page lists the main non-backwards-compatible changes to make it easier for you to upgrade. If you're running into unexpected errors, check the documentation to find out how the specific feature works in scratchattach v2.
4+
5+
1. Generally, `scratchattach` is now imported as / referenced as `sa` (no longer as `scratch3`) in the docs.
6+
2. `session = scratch3.Session("session_id")` was changed to `session = sa.login_by_id("session_id")`
7+
3. `events = scratch3.CloudEvents("project_id")` was changed to `events = sa.get_cloud("project_id").events()`
8+
4. `client = scratch3.CloudRequests(conn)` was changed to `client = session.connect_cloud("project_id").requests()`
9+
5. `value = scratch3.get_var("project_id", "variable")` was changed to
10+
```py
11+
cloud = sa.get_cloud("project_id") # This function is ran once
12+
value = cloud.get_var("variable") # This function can safely be called in a loop without spamming an API
13+
```
14+
The same applies to getting TurboWarp cloud variables.
15+
16+
6. All comments are now represented by `sa.Comment` objects
17+
7. All activites and messages are now represented by `sa.Activity` objects
18+
8. Projects and studios are now always represented by `sa.Project` and `sa.Studio` objects, never as dicts
19+
9. project.get_comment was changed to project.comment_by_id
20+
10. Generally, many functions that used to start with ".get_" had the "get_" removed from their names.
21+
11. If an attribute refers to a username, it is now always ".username" and not ".user"
22+
12. `CloudConnection` and `TwCloudConnection` don't exist anymore. Instead, there are now `Cloud` and `TwCloud` objects that not only handle setting cloud variables, but also have built in functions for getting variables very frequently without spamming the API (new CloudRecorder infrastracture).
23+
13. `TwCloudEvents` and `WsCloudEvents` were merged into `CloudEvents`. The formerly called `CloudEvents` are now `CloudLogEvents`
24+
14. `TwCloudRequests` and `CloudRequests` were merged into `CloudRequests`
25+
15. All events are now always ran in threads by default. You can disable this using `@events.event(thread=False)`
26+
16. Cloud Request Events don't use the `id` attribute anymore. Instead, they use the `request_id` attribute.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Scratchattach provides a submodule `editor` for project parsing/editing. It is useful for extracting data from projects, or performing repetitive operations.
2+
3+
> [!NOTE]
4+
> Scratchattach.editor is work-in-progress. If there is a feature missing or a strange bug, [please add an issue!](https://github.com/TimMcCool/scratchattach/issues)
5+
6+
# Basic usage
7+
8+
### import scratchattach.editor:
9+
```py
10+
from scratchattach import editor
11+
```
12+
13+
### Load a project
14+
```py
15+
# from a sb3 filepath:
16+
proj = editor.Project.from_sb3("test proj.sb3")
17+
18+
# from a binary file
19+
with open("test proj.sb3", "rb") as f:
20+
proj = editor.Project.from_sb3(f)
21+
22+
# from a bytes
23+
with open("test proj.sb3", "rb") as f:
24+
sb3_bytes = f.read()
25+
proj = editor.Project.from_sb3(sb3_bytes)
26+
27+
# from a project id
28+
proj = editor.Project.from_id(104) # Project<name=Weekend, meta=Meta<3.0.0 : 0.1.0 : scratchattach.editor by https://scratch.mit.edu/users/timmccool/>>
29+
```
30+
31+
### View project attributes
32+
```py
33+
# print project name, if applicable (inferred from project title, or file name)
34+
print(proj.name) # test proj
35+
36+
# print project assets (costumes and sounds in all sprites)
37+
for asset in proj.assets:
38+
print(asset)
39+
40+
# View turbowarp configuration
41+
print(proj.tw_config)
42+
43+
# Get comment instance storing twconfig
44+
print(proj.tw_config_comment)
45+
46+
# Get a variable, list or broadcast (including for-this-sprite-only vars)
47+
print(proj.find_vlb("my variable"))
48+
49+
# Get all variables/lists/broadcasts with name
50+
print(proj.find_vlb("my variable", multiple=True)) # if you have a variable and list called 'my variable' this will return a list including both
51+
52+
# print project monitors (variable/list displays)
53+
print(proj.monitors)
54+
55+
# print project metadata
56+
# prints in format {semver} : {vm} : {agent} : {Optional[Platform metadata (used by turbowarp)]}
57+
print(proj.meta) # Meta<3.0.0 : 0.1.0 : scratchattach.editor by https://scratch.mit.edu/users/timmccool/: PlatformMeta(name='TurboWarp', url='https://turbowarp.org/')>
58+
59+
# view extensions that are used by the project (this may not work with old scratch projects)
60+
print(proj.extensions) # [Extension(code='pen', name='Pen Extension')]
61+
62+
# SUBJECT TO CHANGE: Add a monitor to the project
63+
vlb = proj.find_vlb('var')
64+
m = editor.Monitor(vlb, visible=True, params={
65+
"VARIABLE": vlb.name
66+
})
67+
68+
proj.add_monitor(m)
69+
```
70+
71+
> [!WARNING]
72+
> Loading scripts from the backpack requires a special function: editor.load_script_from_backpack, because the backpack uses a
73+
> slightly different block syntax

0 commit comments

Comments
 (0)