Spaces:
Paused
Paused
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from rich import print
|
| 3 |
+
app = FastAPI()
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
Home = {
|
| 7 |
+
"bulb": {
|
| 8 |
+
"discription": "bed room light only",
|
| 9 |
+
"value": 0,
|
| 10 |
+
"can be": [0, 1],
|
| 11 |
+
"pin": "D1"
|
| 12 |
+
},
|
| 13 |
+
"fan": {
|
| 14 |
+
"discription": "hall fan",
|
| 15 |
+
"value": 0,
|
| 16 |
+
"can be": [0, 1, 2, 3, 4, 5],
|
| 17 |
+
"pin": "D3"
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@app.get("/")
|
| 23 |
+
def read_root():
|
| 24 |
+
return {"message": "Welcome to this fantastic app!"}
|
| 25 |
+
|
| 26 |
+
@app.get("/home")
|
| 27 |
+
def read_home():
|
| 28 |
+
global Home
|
| 29 |
+
print(Home)
|
| 30 |
+
return Home
|
| 31 |
+
|
| 32 |
+
@app.post("/home")
|
| 33 |
+
def write_home(data: dict):
|
| 34 |
+
global Home
|
| 35 |
+
Home = data
|
| 36 |
+
print(Home)
|
| 37 |
+
return Home
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
import uvicorn
|
| 42 |
+
uvicorn.run(app, host="127.0.0.1", port=7680)
|