-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent-test.py
More file actions
26 lines (20 loc) · 979 Bytes
/
Event-test.py
File metadata and controls
26 lines (20 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import scratchattach as sa
from getpass import getpass
session = sa.login(input("What's your username?\n"), getpass("What's your password? (hidden in terminal)")) # Log in to Scratch
cloud = session.connect_scratch_cloud(input("What's the project id?\n")) # Connect Scratch's cloud
events = cloud.events()
@events.event
def on_set(activity): #Called when a cloud var is set
print(f"Variable {activity.var} was set to the value {activity.value} at {activity.timestamp}")
# `activity` is a sa.CloudActivity object
# To get the user who set the variable, call activity.load_log_data() which saves the username to the activity.username attribute
@events.event
def on_del(activity):
print(f"{activity.user} deleted variable {activity.var}")
@events.event
def on_create(activity):
print(f"{activity.user} created variable {activity.var}")
@events.event #Called when the event listener is ready
def on_ready():
print("Event listener ready!")
events.start()