Start timetable checker
This commit is contained in:
@@ -3,8 +3,12 @@ import paho.mqtt.client as mqttClient
|
|||||||
import paho.mqtt.publish as publish
|
import paho.mqtt.publish as publish
|
||||||
|
|
||||||
from sqlmodel import select
|
from sqlmodel import select
|
||||||
|
from fastapi import Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import selectinload
|
||||||
|
import sqlalchemy.exc as exc
|
||||||
|
import datetime
|
||||||
|
|
||||||
from app.services.database import Session, get_session, Depends
|
from app.services.database import Session, get_session
|
||||||
from app.model.models import *
|
from app.model.models import *
|
||||||
|
|
||||||
doorIsOpen = True
|
doorIsOpen = True
|
||||||
@@ -29,7 +33,17 @@ def isDoorOpen():
|
|||||||
return doorIsOpen
|
return doorIsOpen
|
||||||
|
|
||||||
def checkAccess(uuid: str, db: Session = Depends(get_session)):
|
def checkAccess(uuid: str, db: Session = Depends(get_session)):
|
||||||
|
try:
|
||||||
|
current_weekday = datetime.datetime.weekday(datetime.date.today())
|
||||||
|
print(f"current day is {current_weekday}")
|
||||||
card = db.exec(select(Card).where(Card.uuid == uuid)).one()
|
card = db.exec(select(Card).where(Card.uuid == uuid)).one()
|
||||||
print(card.group.accessauths.timetables)
|
for auth in card.group.accessauths:
|
||||||
|
print(f"checking auth: {auth.name}")
|
||||||
|
for timetable in auth.timetables:
|
||||||
|
print(f"timetable date is {timetable.weekday - 1}")
|
||||||
|
if current_weekday == timetable.weekday - 1:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
except exc.NoResultFound:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user