From eac465e1a8ce58480cfb48c5e20c44bcce7b83f1 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Thu, 2 May 2024 18:27:38 +0200 Subject: [PATCH] Maybe fixed write endpoint? --- src/endpoints/bettwaage.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/endpoints/bettwaage.py b/src/endpoints/bettwaage.py index 6c2abf5..a3ee5c3 100644 --- a/src/endpoints/bettwaage.py +++ b/src/endpoints/bettwaage.py @@ -9,6 +9,7 @@ import csv router = APIRouter() file_path = "bettwaage.csv" +header = "timestamp;tl;tr;bl;br;total;" latest_values = [] zero_values = [0, 0, 0, 0] @@ -16,7 +17,7 @@ scale_values = [1, 1, 1, 1] 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") @@ -90,7 +91,7 @@ async def get_latest(): @router.delete("/delete", tags=["file"]) async def delete_file(): 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" @@ -113,4 +114,4 @@ async def set_scales(tl: float, tr: float, bl: float, br: float): if not os.path.exists(file_path): - add_line_to_history("timestamp;tl;tr;bl;br;total;") + add_line_to_history(header)