Added basic history setup

This commit is contained in:
Maximilian Giller 2023-10-25 17:44:45 +02:00
parent 8fec41ae33
commit 8829447f94
2 changed files with 19 additions and 0 deletions

13
src/history.py Normal file
View file

@ -0,0 +1,13 @@
import csv
def get_recent_entries(path: str, count: int) -> list[dict]:
"""Get the most recent entries from a csv file"""
with open(path, "r") as f:
reader = csv.DictReader(f)
entries = list(reader)
entries = [
{"timestamp": entry[0], "temperature": entry[1], "humidity": entry[2]}
for entry in entries
]
return entries[-count:]

View file

@ -108,6 +108,12 @@ async def humidity():
return measurements
@app.post("/history")
async def history():
day_entry_count = 24 * 60
return get_recent_entries("history.csv", day_entry_count)
@app.post("/flash")
async def flash(count: int = 1):
global should_run_time_loop