summaryrefslogtreecommitdiff
path: root/example.py
blob: c717ef2285c36b7e3c414bc8b5f58ebddb2a2d92 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
blockext spec
for tim
because he's too good for a doc file

Example code:
"""

import blockext

blockext.PORT = 1234

@blockext.predicate("/tf")
def tf():
    blockspec = "true or false"
    return random.choice(True, False)


@blockext.reporter("/weather", blocking=True)
def weather(city):
    blockspec = "current weather in %s"
    return weatherIn(city)

@blockext.reporter("/light")
def light():
    blockspec = "light sensor value"
    return lightsensor.get()

@blockext.stack("/move")
def move(degrees):
    blockspec = "move %n degrees"
    move(degrees)

blockext.generate_extension(blockext.SCRATCH, "extension.json")
blockext.generate_extension(blockext.SNAP, "extension.xml")
if __name__ == "__main__":
    blockext.run()


# I suppose a launcher could do that on demand

# Or run() could do it for you. Really I wanted you to think about *why* you're
# doing stuff.