Skip to content

Commit 04f0ed1

Browse files
committed
first commit
0 parents  commit 04f0ed1

7 files changed

Lines changed: 162 additions & 0 deletions

File tree

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Ignore enviroment variables
2+
app.env
3+
#Ignore python virtual enviroment
4+
pyvenv.cfg
5+
bin/
6+
include/
7+
lib/
8+
lib64
9+
lib64

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contribution guidelines
2+
3+
This program uses scratchattach to get the variables and set them, so you need familiarity with Python and scratchattach to contribute.
4+
5+
## What to contribute?
6+
7+
Here are the types of contribution we welcome:
8+
9+
- Contributions that fix an issue.
10+
- Add a planned feature.
11+
- QOL improvements
12+
13+
We may also merge a pull request containing new features if it is stable, improves the program, and doesn't interfere with other features.
14+
15+
## Styling Suggestions
16+
17+
- Use 4 space indentation in code to help it make it more readable.
18+
- Add short, descriptive, and clear descriptions for functions you make. This makes it easier for someone to understand exactly what the function does.
19+
20+
## Making the pull request
21+
22+
You may want to enable editing for maintainers to allow maintainers to improve the code before merging the pull request instead of changing it after they just merged the pull request.
23+
24+
You want the pull request's title to be as descriptive as possible in the fewest words possible.
25+
26+
When you type the request, you have to mention what issue it fixes (We recommend you also make an issue about the thing you want to add/remove/fix to make discussion easier), what changes you exactly made, and in which environment you tested the changes you made.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 zaid1442011 (Github user)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
# scratch-cloud-variable-sync
3+
4+
A python script to sync Scratch's cloud variables to Turbowarp's cloud server.
5+
6+
## Current features
7+
8+
- Sync cloud variables from Scratch to another cloud server.
9+
10+
## Planned features
11+
12+
- Enable 2-way communication between projects
13+
14+
- Add proper error handling
15+
16+
- Add more customizable settings
17+
18+
## Installation
19+
20+
These instructions are for Unix-based operating systems only (macOS, BSD, and Linux).
21+
22+
1. The first step is to clone the repository or download the [.zip file](https://github.com/zaid1442011/scratch-cloud-variable-sync/archive/refs/heads/main.zip) of the repository. By opening the terminal and typing:
23+
24+
```sh
25+
git clone https://github.com/zaid1442011/scratch-cloud-variable-sync.git
26+
```
27+
28+
If you don't have git, [install it](https://git-scm.com/downloads) or extract the [.zip file](https://github.com/zaid1442011/scratch-cloud-variable-sync/archive/refs/heads/main.zip) to the home folder.
29+
30+
2. Change directory to the repository:
31+
32+
```sh
33+
cd scratch-cloud-variable-sync
34+
```
35+
36+
3. (Recommended) Make a python virtual environment
37+
```sh
38+
python3 -m venv .
39+
```
40+
And activate it (Note: You need to do this every time you deactivate the virtual environment or close the terminal session.)
41+
```sh
42+
source ./bin/activate
43+
```
44+
45+
4. Install the required dependencies
46+
```sh
47+
pip3 install -r requirements.txt
48+
```
49+
50+
5. Copy the contents off the example.env folder and create an 'app.env' text file and paste the contents of 'example.env' there. Fill the fields in the newly created 'app.env' with their respective values.
51+
52+
6. Start the script
53+
```sh
54+
python3 app.py
55+
```
56+
57+
## Contributing
58+
59+
All contributions are welcome, but they must abide by our contribution guidelines.
60+
61+
## Help
62+
63+
If you have any question, suggestions, or encounter any issues. File an issue [here](https://github.com/zaid1442011/scratch-cloud-variable-sync/issues).

app.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#Import modules
2+
import scratchattach as scratch3
3+
from dotenv import load_dotenv
4+
import os
5+
6+
#Load the .env file(s)
7+
load_dotenv('app.env')
8+
9+
#Set variables to the environment variables
10+
username=os.getenv('username')
11+
scratch_project=os.getenv('scratch_project')
12+
server=os.getenv('cloud_host')
13+
contact_info=os.getenv('contact')
14+
15+
#Connect to Turbowarp's cloud server or another cloud server
16+
turbo_conn = scratch3.TwCloudConnection(project_id=scratch_project, username=username, cloud_host=server, purpose="A bot that syncs Scratch variables to another cloud server", contact=contact_info)
17+
18+
set_vars = None
19+
while True:
20+
#Get a dictionary of the cloud variables on Scratch
21+
variables = scratch3.get_cloud(scratch_project)
22+
#Sets these variables in Turbowarp
23+
if set_vars == variables: continue
24+
for var in variables:
25+
turbo_conn.set_var(var, variables[var])
26+
set_vars = variables.copy()

example.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Make a new file called 'app.env' and put the variables and values there.
2+
username="" # A username for the cloud connection to the cloud server being updated. (Note that Turbowarp will block the connection if the username isn't an existing one, for a Scratch Team member, or isn't "player" followed by 2 to 7 digits)
3+
scratch_project="" # Put your project ID here
4+
cloud_host="" # The cloud server which this script will update (use "wss://clouddata.turbowarp.org" for the North American server, or "wss://clouddata-eu.turbowarp.org" for the European cloud server)
5+
contact="" # Put your contact info or turbowarp may block your request.

requirements.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
beautifulsoup4==4.12.3
2+
bs4==0.0.2
3+
certifi==2024.7.4
4+
charset-normalizer==3.3.2
5+
idna==3.7
6+
numpy==2.0.1
7+
python-dotenv==1.0.1
8+
requests==2.32.3
9+
scratchattach==1.7.3
10+
soupsieve==2.5
11+
urllib3==2.2.2
12+
websocket-client==1.8.0

0 commit comments

Comments
 (0)