Discuss Scratch

uukelele
Scratcher
12 posts

scratchattach - A Scratch API wrapper (Python)

wvzack wrote:

This is just a help message for those who are having trouble installing scratchattach and get the error somewhat like unknown command pip: try searching your disk for “pip” after a bit you (if you installed pip) will see something like pipxxx.exe eg. For me it's pip311.exe, after run pip311 (or whatever it is) install -u scratchattach

searching disk is harder, just write a new python script:

import sys
import subprocess
result = subprocess.run([sys.executable, '-m', 'pip', 'install', 'scratchattach', '-U'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print(result.stdout.decode())
print(result.stderr.decode())

note: it will take some time, you will see a blank screen until the entire thing is done then it will show the output
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

uukelele wrote:

wvzack wrote:

This is just a help message for those who are having trouble installing scratchattach and get the error somewhat like unknown command pip: try searching your disk for “pip” after a bit you (if you installed pip) will see something like pipxxx.exe eg. For me it's pip311.exe, after run pip311 (or whatever it is) install -u scratchattach

searching disk is harder, just write a new python script:

import sys
import subprocess
result = subprocess.run([sys.executable, '-m', 'pip', 'install', 'scratchattach', '-U'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print(result.stdout.decode())
print(result.stderr.decode())

note: it will take some time, you will see a blank screen until the entire thing is done then it will show the output
Oh ok cool!
kRxZy_kRxZy
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

syncing between tw and scratch, idk if it works
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
    index = 1
uukelele
Scratcher
12 posts

scratchattach - A Scratch API wrapper (Python)

kRxZy_kRxZy wrote:

syncing between tw and scratch, idk if it works
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
    index = 1

not gonna work until scratch cloud back up
kRxZy_kRxZy
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

uukelele wrote:

kRxZy_kRxZy wrote:

syncing between tw and scratch, idk if it works
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
    index = 1

not gonna work until scratch cloud back up
I know, can't wait
I've got like 10 scripts to run
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

kRxZy_kRxZy wrote:

uukelele wrote:

kRxZy_kRxZy wrote:

syncing between tw and scratch, idk if it works
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
    index = 1

not gonna work until scratch cloud back up
I know, can't wait
I've got like 10 scripts to run
Why run the var name getter in a loop even if it doesn't fetch anything it still slows it down
kRxZy_kRxZy
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

wvzack wrote:

kRxZy_kRxZy wrote:

uukelele wrote:

kRxZy_kRxZy wrote:

syncing between tw and scratch, idk if it works
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
    index = 1

not gonna work until scratch cloud back up
I know, can't wait
I've got like 10 scripts to run
Why run the var name getter in a loop even if it doesn't fetch anything it still slows it down
Can you expand on what you mean
uukelele
Scratcher
12 posts

scratchattach - A Scratch API wrapper (Python)

kRxZy_kRxZy wrote:

wvzack wrote:

kRxZy_kRxZy wrote:

uukelele wrote:

kRxZy_kRxZy wrote:

syncing between tw and scratch, idk if it works
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
    index = 1

not gonna work until scratch cloud back up
I know, can't wait
I've got like 10 scripts to run
Why run the var name getter in a loop even if it doesn't fetch anything it still slows it down
Can you expand on what you mean

Your code is:
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
index = 1

Better code would be:

import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
variables1 = cloud.get_all_vars()
variables2 = cloud2.get_all_vars() # put these outside the loop so they only run once
while True:
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
index = 1
kRxZy_kRxZy
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

uukelele wrote:

kRxZy_kRxZy wrote:

wvzack wrote:

kRxZy_kRxZy wrote:

uukelele wrote:

kRxZy_kRxZy wrote:

syncing between tw and scratch, idk if it works
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
    index = 1

not gonna work until scratch cloud back up
I know, can't wait
I've got like 10 scripts to run
Why run the var name getter in a loop even if it doesn't fetch anything it still slows it down
Can you expand on what you mean

Your code is:
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
index = 1

Better code would be:

import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
variables1 = cloud.get_all_vars()
variables2 = cloud2.get_all_vars() # put these outside the loop so they only run once
while True:
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
index = 1
This is wrong because the loop doesn't include getting cloud vars, getting them in a loop is safe
kRxZy_kRxZy
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

kRxZy_kRxZy wrote:

uukelele wrote:

kRxZy_kRxZy wrote:

wvzack wrote:

kRxZy_kRxZy wrote:

uukelele wrote:

kRxZy_kRxZy wrote:

syncing between tw and scratch, idk if it works
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
    index = 1

not gonna work until scratch cloud back up
I know, can't wait
I've got like 10 scripts to run
Why run the var name getter in a loop even if it doesn't fetch anything it still slows it down
Can you expand on what you mean

Your code is:
import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
while True:
variables1 = cloud.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
variables2 = cloud2.get_all_vars() # returns a dict with the current values of all cloud variables. In v2.0, you can safely use this method in a loop without spamming the API
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
index = 1

Better code would be:

import scratchattach as sa
session = sa.login("USERNAME", "PASSWORD")
index = 1
cloud1 = session.connect_cloud("project_id") # connects any cloud (by default Scratch one's). Returns a sa.ScratchCloud object by default
cloud2 = session.connect_tw_cloud("project_id", purpose="(optional) your use case", contact="(optional) your Scratch account or other contact info")
variables1 = cloud.get_all_vars()
variables2 = cloud2.get_all_vars() # put these outside the loop so they only run once
while True:
cloud1.set_var(f"Cloudvar1", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar2", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar3", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar4", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar5", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar6", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar7", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar8", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar9", "{variables1[index]}")
index += 1
cloud1.set_var(f"Cloudvar10", "{variables1[index]}")
index = 1
cloud2.set_var(f"Cloudvar1", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar2", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar3", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar4", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar5", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar6", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar7", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar8", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar9", "{variables2[index]}")
index += 1
cloud2.set_var(f"Cloudvar10", "{variables2[index]}")
if index == 10:
index = 1
This is wrong because the loop doesn't include getting cloud vars, getting them in a loop is safe
What about this
 import scratchattach as sa
session = sa.login("username", "pw")
project1_cloud = session.connect_tw_cloud("843162693")
project1_events = project1_cloud.events()
project2_cloud = session.connect_cloud("1102436009")
project2_events = project2_cloud.events()
 
@project1_events.event
def on_set(activity):
    project2_cloud.set_var(activity.var, activity.value)
@project2_events.event #remove this for a one way connection
def on_set(activity):
    project1_cloud.set_var(activity.var, activity.value)
 
project1_events.start()
project2_events.start() # remove this for a one way connection
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

kRxZy_kRxZy wrote:

-SNIP-
why do you need to get the vars in the loop? Getting them in the loop will slow down the speed at which turbowarp and scratch variables sync.
kRxZy_kRxZy
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

wvzack wrote:

kRxZy_kRxZy wrote:

-SNIP-
why do you need to get the vars in the loop? Getting them in the loop will slow down the speed at which turbowarp and scratch variables sync.
You need to get them, (the value) or else you will be just setting the cloud vars to the same thing at all times
uukelele
Scratcher
12 posts

scratchattach - A Scratch API wrapper (Python)

kRxZy_kRxZy wrote:

wvzack wrote:

kRxZy_kRxZy wrote:

-SNIP-
why do you need to get the vars in the loop? Getting them in the loop will slow down the speed at which turbowarp and scratch variables sync.
You need to get them, (the value) or else you will be just setting the cloud vars to the same thing at all times

It's a string that you're putting in the set var function anyway, it doesn't matter.

If it was an object, you'd be right, but you could just put in variables.update() anyway.
kRxZy_kRxZy
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

uukelele wrote:

kRxZy_kRxZy wrote:

wvzack wrote:

kRxZy_kRxZy wrote:

-SNIP-
why do you need to get the vars in the loop? Getting them in the loop will slow down the speed at which turbowarp and scratch variables sync.
You need to get them, (the value) or else you will be just setting the cloud vars to the same thing at all times

It's a string that you're putting in the set var function anyway, it doesn't matter.

If it was an object, you'd be right, but you could just put in variables.update() anyway.
oh, ok
The_Impossibles
Scratcher
2 posts

scratchattach - A Scratch API wrapper (Python)

Why… ; - ;
import scratchattach as s3
session = s3.login("Username", "Passwords")
conn = session.connect_cloud("Project IDs")
conn.logs()


It's always return this :
FetchError('HTTPSConnectionPool(host=\'clouddata.scratch.mit.edu\', port=443): Max retries exceeded with url: /logs?projectid=[project ids]&limit=100&offset=0 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x0000021493111250>: Failed to resolve \'clouddata.scratch.mit.edu\' ([Errno 11001] getaddrinfo failed)"))')
bug?

Last edited by The_Impossibles (Feb. 2, 2025 13:18:07)

ababoin07
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

The_Impossibles wrote:

Why… ; - ;
import scratchattach as s3
session = s3.login("Username", "Passwords")
conn = session.connect_cloud("Project IDs")
conn.logs()


It's always return this :
FetchError('HTTPSConnectionPool(host=\'clouddata.scratch.mit.edu\', port=443): Max retries exceeded with url: /logs?projectid=[project ids]&limit=100&offset=0 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x0000021493111250>: Failed to resolve \'clouddata.scratch.mit.edu\' ([Errno 11001] getaddrinfo failed)"))')
bug?
Because cloud variables are brokennnnnnnnnnn
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

uukelele wrote:

kRxZy_kRxZy wrote:

wvzack wrote:

kRxZy_kRxZy wrote:

-SNIP-
why do you need to get the vars in the loop? Getting them in the loop will slow down the speed at which turbowarp and scratch variables sync.
You need to get them, (the value) or else you will be just setting the cloud vars to the same thing at all times

It's a string that you're putting in the set var function anyway, it doesn't matter.

If it was an object, you'd be right, but you could just put in variables.update() anyway.
mb I was kinda stupid sorry
Noah5665
Scratcher
1 post

scratchattach - A Scratch API wrapper (Python)

requests event not working, python is spitting a bunch of errors. Error in console:
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\site-packages\websocket\_http.py”, line 176, in _get_addrinfo_list
addrinfo_list = socket.getaddrinfo(
hostname, port, 0, socket.SOCK_STREAM, socket.SOL_TCP
)
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\socket.py”, line 975, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\threading.py”, line 1041, in _bootstrap_inner
self.run()
~~~~~~~~^^
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\threading.py”, line 992, in run
self._target(*self._args, **self._kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\site-packages\scratchattach\eventhandlers\cloud_events.py”, line 31, in _updater
self.source_cloud.connect()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\site-packages\scratchattach\cloud\cloud.py”, line 27, in connect
super().connect()
~~~~~~~~~~~~~~~^^
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\site-packages\scratchattach\cloud\_base.py”, line 137, in connect
self.websocket.connect(
~~~~~~~~~~~~~~~~~~~~~~^
self.cloud_host,
^^^^^^^^^^^^^^^^
…<4 lines>…
header = self.header
^^^^^^^^^^^^^^^^^^^^
)
^
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\site-packages\websocket\_core.py”, line 256, in connect
self.sock, addrs = connect(
~~~~~~~^
url, self.sock_opt, proxy_info(**options), options.pop(“socket”, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\site-packages\websocket\_http.py”, line 137, in connect
addrinfo_list, need_tunnel, auth = _get_addrinfo_list(
~~~~~~~~~~~~~~~~~~^
hostname, port_from_url, is_secure, proxy
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File “C:\Users\noahc\AppData\Local\Programs\Python\Python313\Lib\site-packages\websocket\_http.py”, line 191, in _get_addrinfo_list
raise WebSocketAddressException(e)
websocket._exceptions.WebSocketAddressException: getaddrinfo failed
The_Impossibles
Scratcher
2 posts

scratchattach - A Scratch API wrapper (Python)

ababoin07 wrote:

The_Impossibles wrote:

Why… ; - ;
import scratchattach as s3
session = s3.login("Username", "Passwords")
conn = session.connect_cloud("Project IDs")
conn.logs()


It's always return this :
FetchError('HTTPSConnectionPool(host=\'clouddata.scratch.mit.edu\', port=443): Max retries exceeded with url: /logs?projectid=[project ids]&limit=100&offset=0 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x0000021493111250>: Failed to resolve \'clouddata.scratch.mit.edu\' ([Errno 11001] getaddrinfo failed)"))')
bug?
Because cloud variables are brokennnnnnnnnnn
oh… -_-
PierreFSGamer
Scratcher
16 posts

scratchattach - A Scratch API wrapper (Python)

tysm TimMcCool for scratchattach. im begginer on it but i too much enjoying the scratchattach My YT Channel

Last edited by PierreFSGamer (Feb. 4, 2025 20:03:33)

Powered by DjangoBB