first commit

This commit is contained in:
2024-07-15 17:55:45 -04:00
commit 853529b871
23 changed files with 454 additions and 0 deletions

107
app/routers/main.py Normal file
View File

@@ -0,0 +1,107 @@
from fastapi import APIRouter
from database import session
from pyowm import OWM
from app.models.auto import Auto_Delivery, Auto_Temp
router = APIRouter(
prefix="/main",
tags=["main"],
responses={404: {"description": "Not found"}},
)
def Average(lst):
return sum(lst) / len(lst)
@router.route("/update", methods=["GET"])
def update_auto():
today_temp = session\
.query(Auto_Temp)\
.order_by(Auto_Temp.id.desc())\
.first()
# get all automatic customers
auto_customers = session\
.query(Auto_Delivery)\
.order_by(Auto_Delivery.last_updated.desc())\
.limit(25)
for f in auto_customers:
pass
return ({"ok": True}), 200
@router.get("/temp")
def update_temp():
temps = []
owm = OWM('21648d8c8d1a4ae495ace0b7810b4d36')
mgr = owm.weather_manager()
# Search for current weather in London (Great Britain) and get details
observation = mgr.weather_at_place('Worcester, US')
w = observation.weather
temp_dict_kelvin = w.temperature() # a dict in Kelvin units (default when no temperature units provided)
temp_dict_kelvin['temp_min']
temp_dict_kelvin['temp_max']
temp_dict_fahrenheit = w.temperature('fahrenheit')
low_temp = temp_dict_kelvin['temp_min']
high_temp = temp_dict_kelvin['temp_max']
temps.append(temp_dict_fahrenheit['temp_max'])
temps.append(temp_dict_fahrenheit['temp_min'])
get_avg = Average(temps)
rounded_temp = round(get_avg)
dday = (65 - ((low_temp + high_temp) /2))
add_new_temp = Auto_Temp(
temp = temp_dict_fahrenheit['temp'],
temp_max = temp_dict_fahrenheit['temp_max'],
temp_min = temp_dict_fahrenheit['temp_min'],
temp_avg = rounded_temp,
degree_day = dday
)
session.add(add_new_temp)
session.commit()
return ({"ok": True}), 200
@router.get("/today")
def auto_today():
today_auto = session.query().filter().first()
return ({"ok": True}), 200
@router.get("/week")
def auto_this_week():
print("here")
return ({"ok": True}), 200
@router.get("/all")
def all_auto():
return ({"ok": True}), 200
@router.get("/completed")
def completed_auto():
return ({"ok": True}), 200