Discuss Scratch

EpicCoderGamer1000
Scratcher
80 posts

scratchattach - A Scratch API wrapper (Python)

TimMcCool wrote:

I added a new page to scratchattach's wiki, it lists different hosting options: https://github.com/TimMcCool/scratchattach/wiki/Hosting
This will become handy someday

epic coder gamer 1000
fiosjeofo
Scratcher
12 posts

scratchattach - A Scratch API wrapper (Python)

NeonCoderFish wrote:

NeonCoderFish wrote:

MonkeyBean2 wrote:

elip100 wrote:

NeonCoderFish wrote:

project = session.connect_project(int(scratch3.get_var(projectid, “arg”)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not ‘NoneType’

I don't like python anymore
It is failing to get the “arg” variable from the project. Make sure the variable exists, is a cloud variable, and you are correctly connected to the project.
argProjectID = scratch3.get_var(projectid, "arg")
if argProjectID:
    project = session.connect_project(int(argProjectID))
    # continue using project, make sure to put the rest of your code that uses this variable in here, unless you make it default to something
else:
    # argProjectID is None, variable "arg" does not exist in the project projectid
Also, consider using scratchattach cloud requests instead of getting the value of “arg” - it will make it much easier to add new features in the future.
everything is perfectly fine ( I checked ) but it just doesn't work
the other thing doesn't work either
maybe make sure the variable projectid is set to the correct one

when green flag clicked
forever
keep coding
have fun
scratch on!
end
define scratch(attach v)
(is cool v)
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<(hi)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
YRANDION
Scratcher
3 posts

scratchattach - A Scratch API wrapper (Python)


@TimMcCool
Hi could you help me with a ScratchAttach script for a Turbowarp project:https://turbowarp.org/1063141008 It is the example @TimMcCool Made but i cant get it to work with turbowarp even though i am using the exmple code from: https://pypi.org/project/scratchattach/

:

import scratchattach as scratch3 conn = scratch3.TwCloudConnection(project_id=“project_id”) #replace with your project id client = scratch3.TwCloudRequests(conn) #optional argument: ignore_exceptions=True @client.request def ping(): #called when client receives request print(“Ping request received”) return “pong” #sends back ‘pong’ to the Scratch project client.run()



by the way i just replaced my project id with 1063141008 but i didnt upload it just incase it became a link
2 minutes ago but i did put in the project id into Python

Last edited by YRANDION (Sept. 5, 2024 02:53:26)

TheCommCraft
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

(#2762)
Now This Server is down?
I can't open it
There has been a problem, it will be fixed soon!

Random Project

spamton.gif





























DUNGEON_EXPLORATION_03_02_23_01
COMPILED VERSION FOR HIGHER SPEED
TheCommCraft
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Is fixed

Random Project

spamton.gif





























DUNGEON_EXPLORATION_03_02_23_01
COMPILED VERSION FOR HIGHER SPEED
wvzack
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

TheCommCraft wrote:

Is fixed
I personally dont use justablock but thanks for making and upkeeping it (I know that if i had had this when i started scratchattach it would of been much simpler)

Likes: Programing (python scratch Lua c++ I am bad at c++ a) Aiviation (B787 Queen of the sky F35) Mountain Biking and Messing around with computers (not a gamer at all)
My projects I am most happy with also the few “polished games I have:
Scratchnosekai
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

I am making a weather forecast, and I want to reflect information such as cloudy, sunny, rainy, etc. in a cloud variable, but I can't convert it to numerical values properly. Is there a good way to do this?

TheCommCraft
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

(#2768)

wvzack wrote:

TheCommCraft wrote:

Is fixed
I personally dont use justablock but thanks for making and upkeeping it (I know that if i had had this when i started scratchattach it would of been much simpler)
Unable to access the link to the authentication destination.
What do you mean?

Random Project

spamton.gif





























DUNGEON_EXPLORATION_03_02_23_01
COMPILED VERSION FOR HIGHER SPEED
TheCommCraft
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

(#2770)

TheCommCraft wrote:

Black-takashi_01 wrote:

(#2768)

wvzack wrote:

TheCommCraft wrote:

Is fixed
I personally dont use justablock but thanks for making and upkeeping it (I know that if i had had this when i started scratchattach it would of been much simpler)
Unable to access the link to the authentication destination.
What do you mean?
I created an account and received a verification email via email and tried to verify, but the link does not work…
try resend mail

Random Project

spamton.gif





























DUNGEON_EXPLORATION_03_02_23_01
COMPILED VERSION FOR HIGHER SPEED
MonkeyBean2
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

Scratchnosekai wrote:

I am making a weather forecast, and I want to reflect information such as cloudy, sunny, rainy, etc. in a cloud variable, but I can't convert it to numerical values properly. Is there a good way to do this?

One way is to convert each possible state to a number, like this:
0: cloudy
1: sunny
2: rainy

Another way is to use scratchattach cloud requests, which can send text by default. This is probably the easier way, although it is not the most efficient, but I don't think that matters for your case, unless you plan on sending weather information for a lot of places at once.


9NAwRfSR-%dWFS$a$g&zBMTj2?;jvS?L5%^X%qpCX|A<*paJ=lU07c)wmt$v{TxL5



scratchGui.timeTravel.year = '2020'
A-MARIO-PLAYER
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

How to resend mail?
go to account settings
go to password
click resend email

moved to @8to16 - this account is an archive





Amp hall of fame
Any posts I made before 2024 are bad posts.
1000th post (no edit)
ban scratch cause you can hack it
i only know 5 digits of pi
quote spam to the extreme
slatch.mit.edu
dying of cringe scratchblocks
Workaround: Summon it





buahauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhau
the laugh is so evil your tiny screen can't comprehend it
Help_For_Games
Scratcher
6 posts

scratchattach - A Scratch API wrapper (Python)

Scratchnosekai wrote:

I am making a weather forecast, and I want to reflect information such as cloudy, sunny, rainy, etc. in a cloud variable, but I can't convert it to numerical values properly. Is there a good way to do this?
To do this, you need to assign numerical values padded with 0s to do this. Then you need to make a Python decoder. I can make an encoder and decoder in Scratch as well as Python.

Here is a scratch example:
https://scratch-mit-edu.ezproxy.canberra.edu.au/projects/1064942022/

And I am too lazy for a Python one. It took ages to make the Scratch. If you want, I can make it later. (the method I have is a gread way to send text from Scratch, or as @MonkeyBean2 suggested:

MonkeyBean2 wrote:

Scratchnosekai wrote:

I am making a weather forecast, and I want to reflect information such as cloudy, sunny, rainy, etc. in a cloud variable, but I can't convert it to numerical values properly. Is there a good way to do this?

One way is to convert each possible state to a number, like this:
0: cloudy
1: sunny
2: rainy

Another way is to use scratchattach cloud requests, which can send text by default. This is probably the easier way, although it is not the most efficient, but I don't think that matters for your case, unless you plan on sending weather information for a lot of places at once.

forever
if <Y E S> then
YES OR ELSE I WILL... DO SOMETHING
end
end
-effortIess-
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

Hey, I have encountered an issue while building a script that processes the comments of a project. The script calls two projects, one with the data (the one from which I get the comments) and another whose Notes and Credits section will be the recipient of the information output from the script. I’ll call the two “source_proj” and “dest_proj” respectively. Right now I’m not doing too much with the data; I just process the comment data into my own object, “oc”.
The point is, getting and processing the comments from source_proj works fine, and produces a set of objects as desired. The problem occurs when the script attempts to write data to dest_proj’s N&C. When I simply try to write a string, like “hello world”, it works fine, but once I start trying to have it write variables and even len() outputs it returns the error
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:673 in set_notes
return self._update_from_dict(r)
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:241 in _update_from_dict
self.author = project
KeyError: “author”


Anyone know why project.py can’t seem to find the data related to the project ID?


Support the suggestion HERE by adding this button to your signature

BAN PI DAY!!! (joke)

100th post
TheCommCraft
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

Black-takashi_01 wrote:

(#2778)
https://panel.justablock.online/
can only create one server…
YOu need to buy resourced from the credits

Random Project

spamton.gif





























DUNGEON_EXPLORATION_03_02_23_01
COMPILED VERSION FOR HIGHER SPEED
-effortIess-
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

-effortIess- wrote:

Hey, I have encountered an issue while building a script that processes the comments of a project. The script calls two projects, one with the data (the one from which I get the comments) and another whose Notes and Credits section will be the recipient of the information output from the script. I’ll call the two “source_proj” and “dest_proj” respectively. Right now I’m not doing too much with the data; I just process the comment data into my own object, “oc”.
The point is, getting and processing the comments from source_proj works fine, and produces a set of objects as desired. The problem occurs when the script attempts to write data to dest_proj’s N&C. When I simply try to write a string, like “hello world”, it works fine, but once I start trying to have it write variables and even len() outputs it returns the error
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:673 in set_notes
return self._update_from_dict(r)
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:241 in _update_from_dict
self.author = project
KeyError: “author”


Anyone know why project.py can’t seem to find the data related to the project ID?
Bump


Support the suggestion HERE by adding this button to your signature

BAN PI DAY!!! (joke)

100th post
TheCommCraft
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

-effortIess- wrote:

(#2782)

-effortIess- wrote:

Hey, I have encountered an issue while building a script that processes the comments of a project. The script calls two projects, one with the data (the one from which I get the comments) and another whose Notes and Credits section will be the recipient of the information output from the script. I’ll call the two “source_proj” and “dest_proj” respectively. Right now I’m not doing too much with the data; I just process the comment data into my own object, “oc”.
The point is, getting and processing the comments from source_proj works fine, and produces a set of objects as desired. The problem occurs when the script attempts to write data to dest_proj’s N&C. When I simply try to write a string, like “hello world”, it works fine, but once I start trying to have it write variables and even len() outputs it returns the error
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:673 in set_notes
return self._update_from_dict(r)
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:241 in _update_from_dict
self.author = project
KeyError: “author”


Anyone know why project.py can’t seem to find the data related to the project ID?
Bump
Maybe give your source code

Random Project

spamton.gif





























DUNGEON_EXPLORATION_03_02_23_01
COMPILED VERSION FOR HIGHER SPEED
MonkeyBean2
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

TheCommCraft wrote:

-effortIess- wrote:

(#2782)

-effortIess- wrote:

Hey, I have encountered an issue while building a script that processes the comments of a project. The script calls two projects, one with the data (the one from which I get the comments) and another whose Notes and Credits section will be the recipient of the information output from the script. I’ll call the two “source_proj” and “dest_proj” respectively. Right now I’m not doing too much with the data; I just process the comment data into my own object, “oc”.
The point is, getting and processing the comments from source_proj works fine, and produces a set of objects as desired. The problem occurs when the script attempts to write data to dest_proj’s N&C. When I simply try to write a string, like “hello world”, it works fine, but once I start trying to have it write variables and even len() outputs it returns the error
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:673 in set_notes
return self._update_from_dict(r)
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:241 in _update_from_dict
self.author = project
KeyError: “author”


Anyone know why project.py can’t seem to find the data related to the project ID?
Bump
Maybe give your source code
It looks like a scratchattach issue, and if this only happens because of improper use then it is an error handling issue, the improper use should throw a helpful descriptive error before something like this happens.

Last edited by MonkeyBean2 (Sept. 13, 2024 14:41:33)



9NAwRfSR-%dWFS$a$g&zBMTj2?;jvS?L5%^X%qpCX|A<*paJ=lU07c)wmt$v{TxL5



scratchGui.timeTravel.year = '2020'
A-MARIO-PLAYER
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

Hi, I need help with this script. This is a script for a project that allows advertising projects. It's supposed to show the name of each project. However, when I add any project, it just says Sandwhich[sic], which is one of the first projects I added to my list. How do I fix this? Server issue or project issue?



Project here: https://scratch-mit-edu.ezproxy.canberra.edu.au/projects/1067783659/

Server code here:
import scratchattach as scratch3
from scratchattach import Encoding as scratchencoder
session = scratch3.login("A-MARIO-PLAYER", REDACTED)
conn = session.connect_cloud("1067783659")
events = scratch3.CloudEvents("1067783659")
import time
@events.event
def on_set(event): #Called when a cloud var is set
    if event.var == "requestid":
      try:
        project = session.connect_project(event.value)
        if project.moderation_status() == "notsafe":
          print("Project is NFE and thus cannot be added.")
          return
        print(f"---\n{project.title}\nby @{project.author}\nID {project.id}")
        print("Responding to request...")
        conn.set_var("response", scratchencoder.encode(f"{project.title}"))
        conn.set_var("response2", project.id)
        print("Added!")
      except:
        print("Failed to respond. Project is probably unshared?")
@events.event #Called when the event listener is ready
def on_ready():
   print("Event listener ready!")
events.start()

Last edited by A-MARIO-PLAYER (Sept. 14, 2024 15:10:06)


moved to @8to16 - this account is an archive





Amp hall of fame
Any posts I made before 2024 are bad posts.
1000th post (no edit)
ban scratch cause you can hack it
i only know 5 digits of pi
quote spam to the extreme
slatch.mit.edu
dying of cringe scratchblocks
Workaround: Summon it





buahauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhauhau
the laugh is so evil your tiny screen can't comprehend it
MonkeyBean2
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

A-MARIO-PLAYER wrote:

Hi, I need help with this script. This is a script for a project that allows advertising projects. It's supposed to show the name of each project. However, when I add any project, it just says Sandwhich[sic], which is one of the first projects I added to my list. How do I fix this? Server issue or project issue?



Project here: https://scratch-mit-edu.ezproxy.canberra.edu.au/projects/1067783659/

Server code here:
import scratchattach as scratch3
from scratchattach import Encoding as scratchencoder
session = scratch3.login("A-MARIO-PLAYER", REDACTED)
conn = session.connect_cloud("1067783659")
events = scratch3.CloudEvents("1067783659")
import time
@events.event
def on_set(event): #Called when a cloud var is set
    if event.var == "requestid":
      try:
        project = session.connect_project(event.value)
        if project.moderation_status() == "notsafe":
          print("Project is NFE and thus cannot be added.")
          return
        print(f"---\n{project.title}\nby @{project.author}\nID {project.id}")
        print("Responding to request...")
        conn.set_var("response", scratchencoder.encode(f"{project.title}"))
        conn.set_var("response2", project.id)
        print("Added!")
      except:
        print("Failed to respond. Project is probably unshared?")
@events.event #Called when the event listener is ready
def on_ready():
   print("Event listener ready!")
events.start()
Maybe your scratch code is not reading the correct response variable, so it always reads the same value? Also using both connect_cloud and cloudevents might create create redundant connections, not sure how exactly it works though. Also, the advertised projects will only persist while the user is online, maybe store the advertised project (and titles) on the server and then add another request type for requesting those stored advertisements. Consider preventing people from adding the same project multiple times, and also maybe store the timestamp for when each advertisement was created so they can be deleted after a certain number of days.


9NAwRfSR-%dWFS$a$g&zBMTj2?;jvS?L5%^X%qpCX|A<*paJ=lU07c)wmt$v{TxL5



scratchGui.timeTravel.year = '2020'
-effortIess-
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

TheCommCraft wrote:

-effortIess- wrote:

(#2782)

-effortIess- wrote:

Hey, I have encountered an issue while building a script that processes the comments of a project. The script calls two projects, one with the data (the one from which I get the comments) and another whose Notes and Credits section will be the recipient of the information output from the script. I’ll call the two “source_proj” and “dest_proj” respectively. Right now I’m not doing too much with the data; I just process the comment data into my own object, “oc”.
The point is, getting and processing the comments from source_proj works fine, and produces a set of objects as desired. The problem occurs when the script attempts to write data to dest_proj’s N&C. When I simply try to write a string, like “hello world”, it works fine, but once I start trying to have it write variables and even len() outputs it returns the error
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:673 in set_notes
return self._update_from_dict(r)
File ~\anaconda3\Lib\site-packages\scratchattach\project.py:241 in _update_from_dict
self.author = project
KeyError: “author”


Anyone know why project.py can’t seem to find the data related to the project ID?
Bump
Maybe give your source code
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 6 10:07:13 2024

@author: ####
"""

import scratchattach as sa

import os

import time

from datetime import datetime

import random

import html #to turn 'Jake &amp Matt' for example to 'Jake & Matt'

def id_sep(txt_in):
seperators = [
'//',
'||',
'+',
'[]',
'][',
' | ',
' -'
]
seperatorsCount = []
s=0
for a in seperators:
seperatorsCount.append(0)
for a in seperators:
seperatorsCount[s] = txt_in.count(seperators[s])
s+=1
id_sep.sep = seperators[seperatorsCount.index(max(seperatorsCount))]

sess = sa.login('USERNAME', 'PASSWORD') #make this universal later

dst_id = 1065223525 #name is necroterra bot test fyi
source_id = 1060658851

class oc:
ocs = {}

#form: name, gender, sexuality, species, role, looks, personality, background
def __init__(self, name, owner, age, gender, sexuality, comment_id):
self.name = name
self.owner = owner
self.age = age
self.comment_id = comment_id
self.gender = gender
self.sexuality = sexuality

@classmethod
def create(cls, name, owner, age, gender, sexuality, comment_id):
obj = cls(name,owner,age,gender,sexuality,comment_id)
cls.ocs[name] = obj

@classmethod
def find(cls, name):
return cls.ocs.get(name, None)

@classmethod
def filter_(cls, predicate):
return [e for e in cls.ocs.values() if predicate(e)]

def scrape_from(project_id):
'''
produces 'noc' number of oc objects. Objects are recorded to list 'objs'
requires scratchattach module to be installed
add 'try' if def is to be used elsewhere

Parameters
----------
project_id : destination project id

Returns
-------
None.

'''

src_proj = sess.connect_project(project_id)

noc=0
objs=[]
while (len(src_proj.comments(limit=40,offset=noc*40))>0):
objs += src_proj.comments(limit=40,offset=noc*40)
time.sleep(random.randint(10,50)/100)
noc+=1
noc=0
for i in objs:
id_sep(html.unescape(objs[noc]['content']))
try:
oc.create(html.unescape(objs[noc]['content']).split(id_sep.sep)[0], objs[noc]['author']['username'], html.unescape(objs[noc]['content']).split(id_sep.sep)[1], html.unescape(objs[noc]['content']).split(id_sep.sep)[2], html.unescape(objs[noc]['content']).split(id_sep.sep)[3], objs[noc]['id'])
except IndexError:
pass
noc+=1

def set_proj_desc(dest_id, field, txt_file):
'''
Sets the description to the previously generated oc list.
Project Notes must not exceed 5000 characters.

Parameters
----------
dest_id : The id of the destination project.
field : 'n' for Notes and Credits, 'i' for instructions.
txt_file : Leave blank for a temp file that will be deleted. Otherwise,
enter the name of the .txt file destination.

Returns
-------
None.

'''
dst_proj = sess.connect_project(dest_id)
try:
dst_file = open(txt_file, 'r+')
except Exception:
print("File not found.")
dst_file = open(txt_file, 'w')
existing_data = dst_file.readlines()
one_line = dst_file.readline()
while one_line:
print(one_line, end=' ')
one_line = dst_file.readline()
test = 'hello world', ' \n anyone there?'
if (field=='n'):
dst_proj.set_notes(dst_file.read())
else:
dst_proj.set_instructions(test)

def identify_self(name):
return (id(name))

def __str__(self, name):
return (name, self.owner, self.age)



dst_file = 'C:/Users/…/necroterra_ocs.txt'
test_proj = sess.connect_project(dst_id)
test = ['apple', 'banana']
oc.scrape_from(source_id)
oc.set_proj_desc(dst_id, 'n', dst_file)

test_dst_proj = sess.connect_project(dst_id)
if (test_dst_proj.notes == ''):
test_dst_proj.set_notes('Last modified at ' + str(datetime.now()))
print(test_dst_proj.notes)

print('\n', datetime.now())
I’m using the SPYDER IDE fyi.

Last edited by -effortIess- (Sept. 16, 2024 16:13:35)



Support the suggestion HERE by adding this button to your signature

BAN PI DAY!!! (joke)

100th post

Powered by DjangoBB