Added basic bettwaage endpoints
This commit is contained in:
parent
6bc569b794
commit
47bd8c2fdd
2 changed files with 33 additions and 0 deletions
31
src/endpoints/bettwaage.py
Normal file
31
src/endpoints/bettwaage.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from os.path import exists
|
||||||
|
|
||||||
|
from fastapi.responses import HTMLResponse
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
file_path = "bettwaage.csv"
|
||||||
|
|
||||||
|
|
||||||
|
def add_line_to_history(line: str) -> None:
|
||||||
|
with open(file_path, "+a", encoding="UTF-8") as fp:
|
||||||
|
fp.writelines([line])
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/file")
|
||||||
|
async def get_file():
|
||||||
|
with open(file_path, "r", encoding="UTF-8") as fp:
|
||||||
|
return HTMLResponse("\n".join(fp.readlines()))
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/add")
|
||||||
|
async def add_weight(tl: int, tr: int, bl: int, br: int):
|
||||||
|
sum = tl + tr + bl + br
|
||||||
|
add_line_to_history(f"{str(datetime.now())};{";".join([tl, tr, bl, br, sum])};")
|
||||||
|
|
||||||
|
|
||||||
|
if not exists(file_path):
|
||||||
|
add_line_to_history("timestamp;tl;tr;bl;br;total;")
|
|
@ -1,9 +1,11 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from endpoints.hue import router as hue_router
|
from endpoints.hue import router as hue_router
|
||||||
|
from endpoints.bettwaage import router as bettwaage_router
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
app.include_router(hue_router, prefix="/hue", tags=["hue"])
|
app.include_router(hue_router, prefix="/hue", tags=["hue"])
|
||||||
|
app.include_router(bettwaage_router, prefix="/bettwaage")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run()
|
||||||
|
|
Loading…
Reference in a new issue