-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcollab.py
39 lines (25 loc) · 795 Bytes
/
collab.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
import requests
import random
import time
from urllib.parse import urljoin
HOST = 'http://localhost:5000'
PIN_ENDPOINT = 'pins/'
PINS = urljoin(HOST, PIN_ENDPOINT)
def toggle_color(color: str, state: str):
for pin in requests.get(PINS).json():
if pin['color'] == color:
requests.patch(urljoin(PINS, str(pin)),
json={"state": state})
def switch_all(state: str):
for pin in requests.get(PINS).json():
if pin['state'] != state:
requests.patch(urljoin(PINS, str(pin['id'])),
json={"state": state})
def all_on():
switch_all("on")
def all_off():
switch_all("off")
def color_on(color: str):
toggle_color(color, 'on')
def color_off(color: str):
toggle_color(color, 'off')