A API for scratch with websocket
Project description
Scratch Websocket API
Overview
このライブラリは、Websocketを通じてScratch(またはTurbowarp)に接続し、そのクラウド変数を変更するために作成されました。
Installation
Python3が必須となります。Python2は使えないと思います。
pip install scratch-websocket-api
Usage
Connect
Websocketを使用してサーバーに接続します
import scratch_api.scratch_ws_api as scratch3
conn = scratch3.login("USERNAME", "PASSWORD").connect(ProjectID, max_connections, isScratch)
USERNAME: (string) あなたのユーザー名
PASSWORD: (string) あなたのパスワード
ProjectID: (int) あなたのプロジェクトのID (https://scratch.mit.edu/projects/{projectid})この部分がプロジェクトIDです
max_connections: (int) 最大同時送信数、この数の分、同時に変数を変更できます
isScratch: (boolean or string) TrueならScratch、FalseならTurbowarp、URLを入力すると特定のサーバーに接続できます。
Get Cloud Variable
conn.get(var_NAME)
var_NAME: list 取得するクラウド変数の名前(例: ["Sample1", "Sample2"])
戻り値: list 取得できなかった場合、Noneが返ります。 (例: [200, None]
補足 クラウド変数の取得のみの場合には、最大接続数は0でもOKです
Set Cloud Valiable
conn.set(var_NAME, var_VALUE)
var_NAME: list 変更するクラウド変数の名前(例: ["Sample1", "Sample2"])
var_VALUE: list 変更する数値 (intまたはstr)(例: ["20", 1304])
Sample
import random
import scratch_api.scratch_ws_api as scratch3
conn = scratch3.login("yosshi---_Cloudvar", ".Cloudsession").connect(846708650, 2, True)
conn.send(["1", "2"], [random.randint(1, 10), random.randint(1, 10)])
print(conn.get(["1","2"]))
ランダムに変数を変更するだけの単純なプログラムです
https://scratch.mit.edu/projects/846708650 こちらがそのプロジェクトです
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scratch-websocket-api-0.1.1.tar.gz.
File metadata
- Download URL: scratch-websocket-api-0.1.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
291851a208fe675f84a14a7c6df0c79c9e73e9668d3c5755bfc01b83cda8577c
|
|
| MD5 |
10f710fc1285d3f7034a8f6344b9f55a
|
|
| BLAKE2b-256 |
2563c28ae201e01a3dc179077bca1827357cca6ff118b941b1e95b26456f23f5
|
File details
Details for the file scratch_websocket_api-0.1.1-py3-none-any.whl.
File metadata
- Download URL: scratch_websocket_api-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6991d3c2512da0132097796cb8c7d68a8e6e4d711d1142e63ffe3a541bf7595e
|
|
| MD5 |
12d75976ad772590fd75e17cde619485
|
|
| BLAKE2b-256 |
c9963621110b18c3b061578e67ee471b0d65e74d6df09aebaecd863cdc890e52
|