Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » How do you set cloud variables in python using websockets?
- Classfied3D
-
Scratcher
29 posts
How do you set cloud variables in python using websockets?
Yeah, it is lazy but it works so…I've found a soloution, involving python ‘talking’ to node.js.Your way seems kind of lazy. Its not a very good workaround.
https://replit.com/@Classfied3D/ScratchCloud-installer-V2
It doesn't use websockets, but websockets could look something like this:
import websockets
import asyncio
async def hello(websocket, path):
name = await websocket.recv()
print(f“< {name}”)
greeting = f“Hello {name}!”
await websocket.send(str({“username”: “Classfied3D”, “ProjId”: “513725601”, “method”: “set”, “name”: “☁ test”, “value”: “012345678”}))
print(f“> {greeting}”)
start_server = websockets.serve(hello, “wss/clouddata.scratch.mit.edu/”, 531)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
I'm not really that great at node.js, but someone could read this: https://github.com/trumank/scratch-api/blob/master/scratchapi.js
- Raihan142857
-
Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Maybe try os.environ instead?snipops
i figured out why my code wont work look at this
- ilcheese2Test
-
Scratcher
33 posts
How do you set cloud variables in python using websockets?
Lazy? Its a horrible idea. Its like going around the whole earth to cross a river.Yeah, it is lazy but it works so…I've found a soloution, involving python ‘talking’ to node.js.Your way seems kind of lazy. Its not a very good workaround.
https://replit.com/@Classfied3D/ScratchCloud-installer-V2
It doesn't use websockets, but websockets could look something like this:
import websockets
import asyncio
async def hello(websocket, path):
name = await websocket.recv()
print(f“< {name}”)
greeting = f“Hello {name}!”
await websocket.send(str({“username”: “Classfied3D”, “ProjId”: “513725601”, “method”: “set”, “name”: “☁ test”, “value”: “012345678”}))
print(f“> {greeting}”)
start_server = websockets.serve(hello, “wss/clouddata.scratch.mit.edu/”, 531)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
I'm not really that great at node.js, but someone could read this: https://github.com/trumank/scratch-api/blob/master/scratchapi.js
- SansStudios
-
Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Lazy? Its a horrible idea. Its like going around the whole earth to cross a river.Yeah, it is lazy but it works so…I've found a soloution, involving python ‘talking’ to node.js.Your way seems kind of lazy. Its not a very good workaround.
https://replit.com/@Classfied3D/ScratchCloud-installer-V2
It doesn't use websockets, but websockets could look something like this:
import websockets
import asyncio
async def hello(websocket, path):
name = await websocket.recv()
print(f“< {name}”)
greeting = f“Hello {name}!”
await websocket.send(str({“username”: “Classfied3D”, “ProjId”: “513725601”, “method”: “set”, “name”: “☁ test”, “value”: “012345678”}))
print(f“> {greeting}”)
start_server = websockets.serve(hello, “wss/clouddata.scratch.mit.edu/”, 531)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
I'm not really that great at node.js, but someone could read this: https://github.com/trumank/scratch-api/blob/master/scratchapi.js
I like the fact that the example code uses asyncio instead of threading. Asyncio is easier to deal with imo
- ilcheese2Test
-
Scratcher
33 posts
How do you set cloud variables in python using websockets?
Asyncio is confusing. Threading you technically only need three lines. from threading import Thread a = Thread(target=your_function) a.start()Lazy? Its a horrible idea. Its like going around the whole earth to cross a river.Yeah, it is lazy but it works so…I've found a soloution, involving python ‘talking’ to node.js.Your way seems kind of lazy. Its not a very good workaround.
https://replit.com/@Classfied3D/ScratchCloud-installer-V2
It doesn't use websockets, but websockets could look something like this:
import websockets
import asyncio
async def hello(websocket, path):
name = await websocket.recv()
print(f“< {name}”)
greeting = f“Hello {name}!”
await websocket.send(str({“username”: “Classfied3D”, “ProjId”: “513725601”, “method”: “set”, “name”: “☁ test”, “value”: “012345678”}))
print(f“> {greeting}”)
start_server = websockets.serve(hello, “wss/clouddata.scratch.mit.edu/”, 531)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
I'm not really that great at node.js, but someone could read this: https://github.com/trumank/scratch-api/blob/master/scratchapi.js
I like the fact that the example code uses asyncio instead of threading. Asyncio is easier to deal with imo
- ilcheese2Test
-
Scratcher
33 posts
How do you set cloud variables in python using websockets?
Never mind
Last edited by ilcheese2Test (April 12, 2021 23:38:07)
- SansStudios
-
Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Asyncio is confusing. Threading you technically only need three lines. from threading import Thread a = Thread(target=your_function) a.start()
I just have no idea how to stop threads correctly lol
- Classfied3D
-
Scratcher
29 posts
How do you set cloud variables in python using websockets?
Never mind… still, nothing else is working for me and I already knew how to read cloud variables on python, and I literally suggested everything elseLazy? Its a horrible idea. Its like going around the whole earth to cross a river.Yeah, it is lazy but it works so…I've found a soloution, involving python ‘talking’ to node.js.Your way seems kind of lazy. Its not a very good workaround.
https://replit.com/@Classfied3D/ScratchCloud-installer-V2
It doesn't use websockets, but websockets could look something like this:
import websockets
import asyncio
async def hello(websocket, path):
name = await websocket.recv()
print(f“< {name}”)
greeting = f“Hello {name}!”
await websocket.send(str({“username”: “Classfied3D”, “ProjId”: “513725601”, “method”: “set”, “name”: “☁ test”, “value”: “012345678”}))
print(f“> {greeting}”)
start_server = websockets.serve(hello, “wss/clouddata.scratch.mit.edu/”, 531)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
I'm not really that great at node.js, but someone could read this: https://github.com/trumank/scratch-api/blob/master/scratchapi.js
- ilcheese2Test
-
Scratcher
33 posts
How do you set cloud variables in python using websockets?
Look at my github its somewhere on this topic. Also others seem to be doing the lazy way as wellNever mind… still, nothing else is working for me and I already knew how to read cloud variables on python, and I literally suggested everything elseLazy? Its a horrible idea. Its like going around the whole earth to cross a river.Yeah, it is lazy but it works so…I've found a soloution, involving python ‘talking’ to node.js.Your way seems kind of lazy. Its not a very good workaround.
https://replit.com/@Classfied3D/ScratchCloud-installer-V2
It doesn't use websockets, but websockets could look something like this:
import websockets
import asyncio
async def hello(websocket, path):
name = await websocket.recv()
print(f“< {name}”)
greeting = f“Hello {name}!”
await websocket.send(str({“username”: “Classfied3D”, “ProjId”: “513725601”, “method”: “set”, “name”: “☁ test”, “value”: “012345678”}))
print(f“> {greeting}”)
start_server = websockets.serve(hello, “wss/clouddata.scratch.mit.edu/”, 531)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
I'm not really that great at node.js, but someone could read this: https://github.com/trumank/scratch-api/blob/master/scratchapi.js
Last edited by ilcheese2Test (April 13, 2021 22:28:58)
- ilcheese2Test
-
Scratcher
33 posts
How do you set cloud variables in python using websockets?
Is changing cloud variables using an external server allowed?
- Raihan142857
-
Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Is changing cloud variables using an external server allowed?Yeah, it is. The ST has reviewed projects that did it and they were Safe.
- ilcheese2Test
-
Scratcher
33 posts
How do you set cloud variables in python using websockets?
Stop the thread? I just kill the program ;). The thread isnt a loop. Once if finishes its done the you can start it again if you want. If your function has a loop just use break. Safe meaning they dont stress the server?Asyncio is confusing. Threading you technically only need three lines. from threading import Thread a = Thread(target=your_function) a.start()
I just have no idea how to stop threads correctly lol
Last edited by ilcheese2Test (April 15, 2021 00:23:49)
- PikachuB2005
-
Scratcher
100+ posts
How do you set cloud variables in python using websockets?
I would like to know this as well. Please let me know if you find a way.
Last edited by PikachuB2005 (April 25, 2021 00:58:40)
- ninjaMAR
-
Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
I would like to know this as well. Please let me know if you find a way.Read the whole topic
- Classfied3D
-
Scratcher
29 posts
How do you set cloud variables in python using websockets?
Try this: os.environ (I can’t do straight quotes)Half the time it just returns nullos.getenv() is equivalent to os.environ.get()Maybe try os.environ instead?snipops
i figured out why my code wont work look at this
- ninjaMAR
-
Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Try this: os.environ (I can’t do straight quotes)I figured it out
- Classfied3D
-
Scratcher
29 posts
How do you set cloud variables in python using websockets?
Okay, after my node.js connection thingy that was really lazy, I made a python-only one.
To get vars use ws.recv() in an infinite loop on a thread
My new version: https://github.com/Classfied3D/ScratchCloudV4
To get vars use ws.recv() in an infinite loop on a thread
My new version: https://github.com/Classfied3D/ScratchCloudV4
- Discussion Forums
- » Advanced Topics
-
» How do you set cloud variables in python using websockets?


/clouddata.scratch.mit.edu/”, 531)



