forked from radiorabe/klangbecken
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulate-saemubox.py
44 lines (34 loc) · 1018 Bytes
/
simulate-saemubox.py
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
44
import pathlib
import random
import sys
import time
here = pathlib.Path(__file__).parent.resolve()
root = here.parent.parent
sys.path.append(str(root))
from klangbecken.player import LiquidsoapClient # noqa: E402
print("Simulating the virtual Sämubox")
print("------------------------------", end="")
on_air = True
duration = 3
ls_client = LiquidsoapClient(str(root / "klangbecken.sock"))
with ls_client:
ls_client.command("klangbecken.on_air True")
i = 0
while True:
if i % 24 == 0:
print(f"\nDay {i//24 + 1: >3}: ", end="")
i += 1
duration -= 1
if on_air:
print("+", end="", flush=True)
else:
print("_", end="", flush=True)
if duration == 0:
on_air = not on_air
with ls_client:
ls_client.command(f"klangbecken.on_air {on_air}")
if on_air:
duration = random.choice([1, 2, 3, 3, 4, 4, 5, 6])
else:
duration = random.choice([1, 1, 2, 2, 3, 4])
time.sleep(36) # Sleep for one "hour"