-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
39 lines (32 loc) · 862 Bytes
/
api.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
from fastapi import FastAPI
from pydantic import BaseModel
from tasks import spiral, random_led, top_down, sides
import uvicorn
app = FastAPI()
class Item(BaseModel):
name: str
reverse: bool
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.post("/tree")
async def tree(item: Item):
if item.name == 'spiral':
spiral.delay()
elif item.name == 'random_led':
random_led.delay()
elif item.name == 'top_down':
if not item.reverse:
top_down.delay(True)
else:
top_down.delay(False)
elif item.name == 'sides':
if not item.reverse:
sides.delay(True)
else:
sides.delay(False)
else:
return 'No name recognized'
return item
if __name__ == '__main__':
uvicorn.run(app, port=8000, host='*')