Maybe fixed write endpoint?

This commit is contained in:
Maximilian Giller 2024-05-02 18:27:38 +02:00
parent ed1f6a7475
commit eac465e1a8

View file

@ -9,6 +9,7 @@ import csv
router = APIRouter() router = APIRouter()
file_path = "bettwaage.csv" file_path = "bettwaage.csv"
header = "timestamp;tl;tr;bl;br;total;"
latest_values = [] latest_values = []
zero_values = [0, 0, 0, 0] zero_values = [0, 0, 0, 0]
@ -16,7 +17,7 @@ scale_values = [1, 1, 1, 1]
def add_line_to_history(line: str) -> None: def add_line_to_history(line: str) -> None:
with open(file_path, "a", encoding="UTF-8") as fp: with open(file_path, "a") as fp:
fp.write(line + "\n") fp.write(line + "\n")
@ -90,7 +91,7 @@ async def get_latest():
@router.delete("/delete", tags=["file"]) @router.delete("/delete", tags=["file"])
async def delete_file(): async def delete_file():
os.remove(file_path) os.remove(file_path)
add_line_to_history("timestamp;tl;tr;bl;br;total;") add_line_to_history(header)
return "Deleted file and created new file with headers" return "Deleted file and created new file with headers"
@ -113,4 +114,4 @@ async def set_scales(tl: float, tr: float, bl: float, br: float):
if not os.path.exists(file_path): if not os.path.exists(file_path):
add_line_to_history("timestamp;tl;tr;bl;br;total;") add_line_to_history(header)