Skip to main content

A API for scratch with websocket

Project description

Scratch Websocket API

Overview

このライブラリは、Websocketを通じてScratch(またはTurbowarp)に接続し、そのクラウド変数を変更するために作成されました。
制作者: yosshi---

Installation

Python3が必須となります。Python2は使えないと思います。

pip install scratch-websocket-api websocket-client requests

websocket-clientとrequestsはこのライブラリで必要なのでインストールしてください。

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---", "PASSWORD").connect(846708650, 2, True)
conn.send(["1", "2"], [random.randint(1, 10), random.randint(1, 10)])  
print(conn.get(["1","2"]))

ランダムに変数を変更するだけの単純なプログラムです

こちらがそのプロジェクトです

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scratch-websocket-api-0.1.7.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scratch_websocket_api-0.1.7-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file scratch-websocket-api-0.1.7.tar.gz.

File metadata

  • Download URL: scratch-websocket-api-0.1.7.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for scratch-websocket-api-0.1.7.tar.gz
Algorithm Hash digest
SHA256 4f4b5b715f8668de2bc7df67a1816fa16843ff5f21a22c9de158e5b2baea54f0
MD5 5b276a36c04f5c22fdd800fe920e7b59
BLAKE2b-256 0adca4ebe9035eb470efea587cbab5e7397aec2aff120658d7613253792b7f63

See more details on using hashes here.

File details

Details for the file scratch_websocket_api-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for scratch_websocket_api-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0e70788c23144a92ca72802066cf1821ec3195a0fc0329792d4223a28533bc6d
MD5 422817798bf8b3eebb0bf24829255cc0
BLAKE2b-256 697dbee87889fa76530c27e31d48dc56d055c1b3815cbc830bc90a295c50d984

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page