Commit ·
fa23469
1
Parent(s): a986503
html
Browse files
app.py
CHANGED
|
@@ -1,13 +1,51 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
-
state = [0,0,0,0,
|
|
|
|
| 5 |
|
| 6 |
@app.get("/")
|
| 7 |
def greet_json():
|
| 8 |
# return {"Hello": "World!"}
|
| 9 |
-
return state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
@app.post('/turn/{pos}')
|
| 12 |
def turn(pos):
|
|
|
|
| 13 |
state[int(pos)] = int(not state[int(pos)])
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
+
state = [0,0,0,0,0,0,0,0,0]
|
| 6 |
+
step = '0'
|
| 7 |
|
| 8 |
@app.get("/")
|
| 9 |
def greet_json():
|
| 10 |
# return {"Hello": "World!"}
|
| 11 |
+
# return state
|
| 12 |
+
html_content = """
|
| 13 |
+
<html>
|
| 14 |
+
<head>
|
| 15 |
+
<title>Some HTML in here</title>
|
| 16 |
+
<style>
|
| 17 |
+
.char{
|
| 18 |
+
padding:20px;
|
| 19 |
+
background-color:green;
|
| 20 |
+
}
|
| 21 |
+
.char:even {
|
| 22 |
+
background-color:yellow;
|
| 23 |
+
}
|
| 24 |
+
</style>
|
| 25 |
+
</head>
|
| 26 |
+
<body>"""
|
| 27 |
+
counter = 0
|
| 28 |
+
for i in range(10):
|
| 29 |
+
char = 'X' if state[i] == 0 else '0'
|
| 30 |
+
html_content += '<div><span class="char">' + char + '</span></div>'
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
html_content += """
|
| 36 |
+
</body>
|
| 37 |
+
</html>
|
| 38 |
+
"""
|
| 39 |
+
return HTMLResponse(content=html_content, status_code=200)
|
| 40 |
+
|
| 41 |
+
def change_step():
|
| 42 |
+
global step
|
| 43 |
+
if step == '0':
|
| 44 |
+
step = 'X'
|
| 45 |
+
elif step == 'X':
|
| 46 |
+
step = '0'
|
| 47 |
|
| 48 |
@app.post('/turn/{pos}')
|
| 49 |
def turn(pos):
|
| 50 |
+
change_step()
|
| 51 |
state[int(pos)] = int(not state[int(pos)])
|