Linted
This commit is contained in:
parent
0203e73cd1
commit
d6c9dd61e8
@ -1,5 +1,3 @@
|
||||
from typing import Any
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from pydantic import BaseSettings
|
||||
|
||||
|
22
gru/main.py
22
gru/main.py
@ -1,11 +1,15 @@
|
||||
from typing import Annotated
|
||||
import csv
|
||||
import uvicorn
|
||||
import datetime
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
import uvicorn
|
||||
|
||||
from fastapi import FastAPI, Form
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .core.config import settings
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@ -15,16 +19,22 @@ class Reading(BaseModel):
|
||||
humidity: float
|
||||
age: int
|
||||
|
||||
|
||||
@app.post("/upload", response_model=Reading)
|
||||
def add_reading(temp: Annotated[float, Form()], humidity: Annotated[float, Form()], age: Annotated[int, Form()], device: Annotated[str, Form()]):
|
||||
def add_reading(
|
||||
temp: Annotated[float, Form()],
|
||||
humidity: Annotated[float, Form()],
|
||||
age: Annotated[int, Form()],
|
||||
device: Annotated[str, Form()],
|
||||
):
|
||||
current_datetime = datetime.datetime.now()
|
||||
deducted_datetime = current_datetime - datetime.timedelta(milliseconds=age)
|
||||
append_to_csv(settings.FILE_PATH, temp, humidity, deducted_datetime)
|
||||
return Reading(temperature=temp,humidity=humidity,age=age)
|
||||
return Reading(temperature=temp, humidity=humidity, age=age)
|
||||
|
||||
|
||||
def append_to_csv(filename, temperature, humidity, datetime_var):
|
||||
with open(filename, 'a', newline='') as csvfile:
|
||||
with open(filename, "a", newline="") as csvfile:
|
||||
writer = csv.writer(csvfile)
|
||||
writer.writerow([temperature, humidity, datetime_var])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user