refactor: SQL 쿼리 관리 모듈화 및 메일 관리 UI/UX 고도화

This commit is contained in:
2026-03-17 14:27:25 +09:00
parent 74f11d3bd4
commit d0b33edea8
22 changed files with 851 additions and 1324 deletions

View File

@@ -10,6 +10,7 @@ import pymysql
from datetime import datetime
from playwright.async_api import async_playwright
from dotenv import load_dotenv
from sql_queries import CrawlerQueries
load_dotenv(override=True)
@@ -108,14 +109,7 @@ def crawler_thread_worker(msg_queue, user_id, password):
try:
with conn.cursor() as cursor:
for p_info in captured_data["project_list"]:
sql = """
INSERT INTO projects_master (project_id, project_nm, short_nm, master, continent, country)
VALUES (%s, %s, %s, %s, %s, %s)
ON DUPLICATE KEY UPDATE
project_nm = VALUES(project_nm), short_nm = VALUES(short_nm),
master = VALUES(master), continent = VALUES(continent), country = VALUES(country)
"""
cursor.execute(sql, (p_info.get("project_id"), p_info.get("project_nm"),
cursor.execute(CrawlerQueries.UPSERT_MASTER, (p_info.get("project_id"), p_info.get("project_nm"),
p_info.get("short_nm", "").strip(), p_info.get("master"),
p_info.get("large_class"), p_info.get("mid_class")))
conn.commit()
@@ -168,7 +162,7 @@ def crawler_thread_worker(msg_queue, user_id, password):
if dept and p_id:
with get_db_connection() as conn:
with conn.cursor() as cursor:
cursor.execute("UPDATE projects_master SET department = %s WHERE project_id = %s", (dept, p_id))
cursor.execute(CrawlerQueries.UPDATE_DEPARTMENT, (dept, p_id))
conn.commit()
captured_data["last_project_data"] = None # 초기화
@@ -228,8 +222,7 @@ def crawler_thread_worker(msg_queue, user_id, password):
if current_p_id:
with get_db_connection() as conn:
with conn.cursor() as cursor:
sql = "INSERT INTO projects_history (project_id, crawl_date, recent_log, file_count) VALUES (%s, CURRENT_DATE(), %s, %s) ON DUPLICATE KEY UPDATE recent_log=VALUES(recent_log), file_count=VALUES(file_count)"
cursor.execute(sql, (current_p_id, recent_log, file_count))
cursor.execute(CrawlerQueries.UPSERT_HISTORY, (current_p_id, recent_log, file_count))
conn.commit()
msg_queue.put(json.dumps({'type': 'log', 'message': f' - [성공] 로그: {recent_log[:20]}... / 파일: {file_count}'}))