Graduate

Change query checking method

......@@ -30,7 +30,7 @@ async def send_face(face_list, image_list):
async with websockets.connect(uri) as websocket:
for face, image in zip(face_list, image_list):
#type: np.float32
send = json.dumps({'action': 'register', 'student_id':'2014104149', 'student_name':'정해갑', 'MTCNN': face.tolist()})
send = json.dumps({'action': 'register', 'student_id':'2014101898', 'student_name':'김다솜', 'MTCNN': face.tolist()})
await websocket.send(send)
recv = await websocket.recv()
data = json.loads(recv)
......
......@@ -86,10 +86,10 @@ async def thread(websocket, path):
# 학생을 찾음
sql = "SELECT student_id FROM student WHERE student_id = %s;"
cursor.execute(sql, (student_id))
rows_count = cursor.execute(sql, (student_id))
# DB에 학생이 없으면 등록
if not cursor.fetchone():
if rows_count == 0:
sql = "INSERT INTO student(student_id, student_name) VALUES (%s, %s)"
cursor.execute(sql, (student_id, student_name))
sql = "INSERT INTO lecture_students(lecture_id, student_id) VALUES (%s, %s)"
......@@ -141,10 +141,10 @@ async def thread(websocket, path):
# 인증 성공
# 오늘 이미 출석 됐는지 확인
sql = "SELECT DATE(timestamp) FROM student_attendance WHERE (lecture_id=%s) AND (student_id=%s) AND (DATE(timestamp) = CURDATE());"
cursor.execute(sql, ('0', verified_id))
rows_count = cursor.execute(sql, ('0', verified_id))
# 출석 기록이 없는 경우에만
if not cursor.fetchone():
if rows_count == 0:
# 테이블 맨 뒤에 datetime attribute가 있음. 서버 시간 가져오게 default로 설정해둠.
sql = "INSERT INTO student_attendance(lecture_id, student_id, status) VALUES (%s, %s, %s)"
# TODO: attend / late 처리
......