Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » How do you set cloud variables in python using websockets?
- ilcheese2Test
- Scratcher
33 posts
How do you set cloud variables in python using websockets?
You can install packages on repl with the cube icon on the bar its right above the settings icon. Then install websocket-client. Here is the I dont type that slow. It slowed down for whatever reason.
Last edited by ilcheese2Test (April 8, 2021 18:21:06)
- SansStudios
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
No, it is not this problem. I did import the requests module I just forgot to include it in the post above. Here is my entire code: https://replit.com/@mdub/setting-scratch-cloud-variables-python#main.py . It is a strange glitch. It happens when a user changes the value of a cloud variable in the project but it does not happen every time.https://clouddata.scratch.mit.edu/logs?projectid=512276665&limit=1&offset=0 to detect when a user change cloud variables and sometimes there is a weird error.Sure! Just give me a minute …. I'm making GET requests to
Here is my code:r = requests.get(f'https://clouddata.scratch.mit.edu/logs?projectid={PROJECT_ID}&limit=2&offset=0')The error is:
r = r.json()
- snip -
Can you help me?
Here! So this should workimport requests r = requests.get("https://clouddata.scratch.mit.edu/logs?projectid={PROJECT_ID}&limit=2&offset=0") r = r.json()
Wouldn't it be easier to just wait until you receive data from the cloud via websockets?
You can use
ws = websocket.WebSocket() self.ws.connect(self.WEBSOCKET_SERVER, cookie = cookie, origin = self.SERVER, enable_multithread = True) #setup example # do handshake here received_data = ws.recv() #after setting up a websocket.
Alternatively you can use a websocket application to call a function whenever you receive data. More info on websocket-client here.
Last edited by SansStudios (April 8, 2021 19:22:28)
☁️ scratchcloud ☁️
Click above to check it out! I've worked on it for over a year!
Just like sudden sadness comes hangin' on the breeze
- ninjaMAR
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
I did @Raihan142857 code and I get no errors but the cloud variable never changes
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
- Chiroyce
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Sure will try that.. Could you put it in a try except block. And in the except block print the status code of the connection. Also where are you getting it is it when you set the cloud variable? Is this happening randomly or is it happening whenever your run your program.
April Fools' topics:
— New Buildings in Scratch's headquarters
— Give every Scratcher an M1 MacBook Air
— Scratch should let users edit other Scratchers' projects
— Make a statue for Jeffalo
— Scratch Tech Tips™
— Make a Chiroyce statue emoji
<img src=“x” onerror=“alert('XSS vulnerability discovered')”>
this is a test sentence
- Chiroyce
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Make sure to use the correct username and password, it worked for me when I was using PyCharm on my machine. I did @Raihan142857 code and I get no errors but the cloud variable never changes
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
April Fools' topics:
— New Buildings in Scratch's headquarters
— Give every Scratcher an M1 MacBook Air
— Scratch should let users edit other Scratchers' projects
— Make a statue for Jeffalo
— Scratch Tech Tips™
— Make a Chiroyce statue emoji
<img src=“x” onerror=“alert('XSS vulnerability discovered')”>
this is a test sentence
- Raihan142857
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Also, if your password has a special character, you might have to escape it in the .env fileMake sure to use the correct username and password, it worked for me when I was using PyCharm on my machine. I did @Raihan142857 code and I get no errors but the cloud variable never changes
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
I use scratch.
GF: I'll dump you. BF: hex dump or binary dump?
- ilcheese2Test
- Scratcher
33 posts
How do you set cloud variables in python using websockets?
They are using clouddata.scratch.mit.edu to get changes. Instead of setting the limit to 2 what if you set the limit to a big number and get the first and second results. Also snip bad.No, it is not this problem. I did import the requests module I just forgot to include it in the post above. Here is my entire code: https://replit.com/@mdub/setting-scratch-cloud-variables-python#main.py . It is a strange glitch. It happens when a user changes the value of a cloud variable in the project but it does not happen every time.https://clouddata.scratch.mit.edu/logs?projectid=512276665&limit=1&offset=0 to detect when a user change cloud variables and sometimes there is a weird error.Sure! Just give me a minute …. I'm making GET requests to
Here is my code:r = requests.get(f'https://clouddata.scratch.mit.edu/logs?projectid={PROJECT_ID}&limit=2&offset=0')The error is:
r = r.json()
- snip -
Can you help me?
Here! So this should workimport requests r = requests.get("https://clouddata.scratch.mit.edu/logs?projectid={PROJECT_ID}&limit=2&offset=0") r = r.json()
Wouldn't it be easier to just wait until you receive data from the cloud via websockets?
You can usews = websocket.WebSocket() self.ws.connect(self.WEBSOCKET_SERVER, cookie = cookie, origin = self.SERVER, enable_multithread = True) #setup example # do handshake here received_data = ws.recv() #after setting up a websocket.
Alternatively you can use a websocket application to call a function whenever you receive data. More info on websocket-client here.
Last edited by ilcheese2Test (April 9, 2021 20:29:17)
- SansStudios
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
They are using clouddata.scratch.mit.edu to get changes. Instead of setting the limit to 2 what if you set the limit to a big number and get the first and second results. Also snip bad.
“clouddata.scratch.mit.edu” is what the websockets use. Since websockets are built in, it's much more intuitive to just use the built in ws.recv() (At least thats my opinion). If you have like 8 variables, and all of them are changed at the same time, and you only look at the first 2, you are guaranteed to lose information.
ilcheese2 has a repo that has receiving data built in. Their github is a good reference on this.
Also, what's “snip bad”?
☁️ scratchcloud ☁️
Click above to check it out! I've worked on it for over a year!
Just like sudden sadness comes hangin' on the breeze
- ilcheese2Test
- Scratcher
33 posts
How do you set cloud variables in python using websockets?
I am ilcheese2. Thanks for mentioning mine. It was supposed to be like polyedges api.They are using clouddata.scratch.mit.edu to get changes. Instead of setting the limit to 2 what if you set the limit to a big number and get the first and second results. Also snip bad.
“clouddata.scratch.mit.edu” is what the websockets use. Since websockets are built in, it's much more intuitive to just use the built in ws.recv() (At least thats my opinion). If you have like 8 variables, and all of them are changed at the same time, and you only look at the first 2, you are guaranteed to lose information.
ilcheese2 has a repo that has receiving data built in. Their github is a good reference on this.
Also, what's “snip bad”?
That is snip. Also why does everyone use replit. I did @Raihan142857 code and I get no errors but the cloud variable never changes
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
Last edited by ilcheese2Test (April 9, 2021 21:08:04)
- Raihan142857
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Because we don't have our own computers and we are lazy so an online IDE is our only choiceI am ilcheese2. Thanks for mentioning mine. It was supposed to be like polyedges api.They are using clouddata.scratch.mit.edu to get changes. Instead of setting the limit to 2 what if you set the limit to a big number and get the first and second results. Also snip bad.
“clouddata.scratch.mit.edu” is what the websockets use. Since websockets are built in, it's much more intuitive to just use the built in ws.recv() (At least thats my opinion). If you have like 8 variables, and all of them are changed at the same time, and you only look at the first 2, you are guaranteed to lose information.
ilcheese2 has a repo that has receiving data built in. Their github is a good reference on this.
Also, what's “snip bad”?That is snip. Also why does everyone use replit. I did @Raihan142857 code and I get no errors but the cloud variable never changes
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
I use scratch.
GF: I'll dump you. BF: hex dump or binary dump?
- Classfied3D
- Scratcher
29 posts
How do you set cloud variables in python using websockets?
I've found a soloution, involving python ‘talking’ to node.js.
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
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 Classfied3D (April 10, 2021 16:36:38)
I'm a programmer and this is a signature lol. Checkout my profile.
- Raihan142857
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Read above, we solved the OP's problem with pure python. I've found a soloution, involving python ‘talking’ to node.js.
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 use scratch.
GF: I'll dump you. BF: hex dump or binary dump?
- ninjaMAR
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
I'm using the correct username and passwordAlso, if your password has a special character, you might have to escape it in the .env fileMake sure to use the correct username and password, it worked for me when I was using PyCharm on my machine. I did @Raihan142857 code and I get no errors but the cloud variable never changes
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
- Raihan142857
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Yes, but sometimes if it has a special character you have to escape itI'm using the correct username and passwordAlso, if your password has a special character, you might have to escape it in the .env fileMake sure to use the correct username and password, it worked for me when I was using PyCharm on my machine. I did @Raihan142857 code and I get no errors but the cloud variable never changes
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
For example, if my password is “FreeMoneyFor$1”
in the .env file I would need to put
username=Raihan142857
password=FreeMoneyFor\$1
I use scratch.
GF: I'll dump you. BF: hex dump or binary dump?
- ilcheese2Test
- Scratcher
33 posts
How do you set cloud variables in python using websockets?
My solution is the best. Why are there so many copies of the same exact thing. Also what if you used input(). It might be annoying but it may work.Read above, we solved the OP's problem with pure python. I've found a soloution, involving python ‘talking’ to node.js.
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 10, 2021 21:44:28)
- ilcheese2Test
- Scratcher
33 posts
How do you set cloud variables in python using websockets?
Your way seems kind of lazy. Its not a very good workaround. I've found a soloution, involving python ‘talking’ to node.js.
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 10, 2021 21:50:12)
- ilcheese2Test
- Scratcher
33 posts
How do you set cloud variables in python using websockets?
Is this sarcasm?Because we don't have our own computers and we are lazy so an online IDE is our only choiceI am ilcheese2. Thanks for mentioning mine. It was supposed to be like polyedges api.They are using clouddata.scratch.mit.edu to get changes. Instead of setting the limit to 2 what if you set the limit to a big number and get the first and second results. Also snip bad.
“clouddata.scratch.mit.edu” is what the websockets use. Since websockets are built in, it's much more intuitive to just use the built in ws.recv() (At least thats my opinion). If you have like 8 variables, and all of them are changed at the same time, and you only look at the first 2, you are guaranteed to lose information.
ilcheese2 has a repo that has receiving data built in. Their github is a good reference on this.
Also, what's “snip bad”?That is snip. Also why does everyone use replit. I did @Raihan142857 code and I get no errors but the cloud variable never changes
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
- Raihan142857
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
Sadly, no.Is this sarcasm?Because we don't have our own computers and we are lazy so an online IDE is our only choiceI am ilcheese2. Thanks for mentioning mine. It was supposed to be like polyedges api.They are using clouddata.scratch.mit.edu to get changes. Instead of setting the limit to 2 what if you set the limit to a big number and get the first and second results. Also snip bad.
“clouddata.scratch.mit.edu” is what the websockets use. Since websockets are built in, it's much more intuitive to just use the built in ws.recv() (At least thats my opinion). If you have like 8 variables, and all of them are changed at the same time, and you only look at the first 2, you are guaranteed to lose information.
ilcheese2 has a repo that has receiving data built in. Their github is a good reference on this.
Also, what's “snip bad”?That is snip. Also why does everyone use replit. I did @Raihan142857 code and I get no errors but the cloud variable never changes
https://replit.com/@ninjamar/scratchbridge#run.py
Also please snip
I use scratch.
GF: I'll dump you. BF: hex dump or binary dump?
- Chiroyce
- Scratcher
1000+ posts
How do you set cloud variables in python using websockets?
[removed]
Last edited by Chiroyce (April 11, 2021 16:19:16)
April Fools' topics:
— New Buildings in Scratch's headquarters
— Give every Scratcher an M1 MacBook Air
— Scratch should let users edit other Scratchers' projects
— Make a statue for Jeffalo
— Scratch Tech Tips™
— Make a Chiroyce statue emoji
<img src=“x” onerror=“alert('XSS vulnerability discovered')”>
this is a test sentence
- Discussion Forums
- » Advanced Topics
- » How do you set cloud variables in python using websockets?