Added basic history setup
This commit is contained in:
parent
8fec41ae33
commit
8829447f94
2 changed files with 19 additions and 0 deletions
13
src/history.py
Normal file
13
src/history.py
Normal 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:]
|
|
@ -108,6 +108,12 @@ async def humidity():
|
||||||
return measurements
|
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")
|
@app.post("/flash")
|
||||||
async def flash(count: int = 1):
|
async def flash(count: int = 1):
|
||||||
global should_run_time_loop
|
global should_run_time_loop
|
||||||
|
|
Loading…
Reference in a new issue