Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » scratchattach - A Scratch API wrapper (Python)
- uukelele
-
12 posts
scratchattach - A Scratch API wrapper (Python)
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
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Oh ok cool!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
- kRxZy_kRxZy
-
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
-
12 posts
scratchattach - A Scratch API wrapper (Python)
syncing between tw and scratch, idk if it worksimport 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
-
1000+ posts
scratchattach - A Scratch API wrapper (Python)
I know, can't waitsyncing between tw and scratch, idk if it worksimport 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've got like 10 scripts to run
- wvzack
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Why run the var name getter in a loop even if it doesn't fetch anything it still slows it downI know, can't waitsyncing between tw and scratch, idk if it worksimport 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've got like 10 scripts to run
- kRxZy_kRxZy
-
1000+ posts
scratchattach - A Scratch API wrapper (Python)
Can you expand on what you meanWhy run the var name getter in a loop even if it doesn't fetch anything it still slows it downI know, can't waitsyncing between tw and scratch, idk if it worksimport 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've got like 10 scripts to run
- uukelele
-
12 posts
scratchattach - A Scratch API wrapper (Python)
Can you expand on what you meanWhy run the var name getter in a loop even if it doesn't fetch anything it still slows it downI know, can't waitsyncing between tw and scratch, idk if it worksimport 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've got like 10 scripts to run
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
-
1000+ posts
scratchattach - A Scratch API wrapper (Python)
This is wrong because the loop doesn't include getting cloud vars, getting them in a loop is safeCan you expand on what you meanWhy run the var name getter in a loop even if it doesn't fetch anything it still slows it downI know, can't waitsyncing between tw and scratch, idk if it worksimport 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've got like 10 scripts to run
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
-
1000+ posts
scratchattach - A Scratch API wrapper (Python)
What about thisThis is wrong because the loop doesn't include getting cloud vars, getting them in a loop is safeCan you expand on what you meanWhy run the var name getter in a loop even if it doesn't fetch anything it still slows it downI know, can't waitsyncing between tw and scratch, idk if it worksimport 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've got like 10 scripts to run
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
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
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
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. -SNIP-
- kRxZy_kRxZy
-
1000+ posts
scratchattach - A Scratch API wrapper (Python)
You need to get them, (the value) or else you will be just setting the cloud vars to the same thing at all timeswhy 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. -SNIP-
- uukelele
-
12 posts
scratchattach - A Scratch API wrapper (Python)
You need to get them, (the value) or else you will be just setting the cloud vars to the same thing at all timeswhy 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. -SNIP-
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
-
1000+ posts
scratchattach - A Scratch API wrapper (Python)
oh, okYou need to get them, (the value) or else you will be just setting the cloud vars to the same thing at all timeswhy 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. -SNIP-
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.
- The_Impossibles
-
2 posts
scratchattach - A Scratch API wrapper (Python)
Why… ; - ;
It's always return this :
bug?
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)"))')
Last edited by The_Impossibles (Feb. 2, 2025 13:18:07)
- ababoin07
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
Because cloud variables are brokennnnnnnnnnn Why… ; - ;import scratchattach as s3 session = s3.login("Username", "Passwords") conn = session.connect_cloud("Project IDs") conn.logs()
It's always return this :bug?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)"))')
- wvzack
-
500+ posts
scratchattach - A Scratch API wrapper (Python)
mb I was kinda stupid sorryYou need to get them, (the value) or else you will be just setting the cloud vars to the same thing at all timeswhy 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. -SNIP-
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.
- Noah5665
-
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
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
-
2 posts
scratchattach - A Scratch API wrapper (Python)
oh… -_-Because cloud variables are brokennnnnnnnnnn Why… ; - ;import scratchattach as s3 session = s3.login("Username", "Passwords") conn = session.connect_cloud("Project IDs") conn.logs()
It's always return this :bug?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)"))')
- PierreFSGamer
-
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)
- Discussion Forums
- » Advanced Topics
-
» scratchattach - A Scratch API wrapper (Python)