마켓 분석 데이터 추가

This commit is contained in:
jaehwang committed 2026-05-19 15:45:44 +09:00
1 parent cda518c027
commit 20fdf53264
6 files changed
+91 -17

No files matched your search

+22
View File
@@ -59,6 +59,17 @@ async def fetchone(sql: str, args: tuple = ()) -> dict | None:
finally:
conn.close()
async def fetchall(sql: str, args: tuple = ()) -> list[dict]:
pool = await get_pool()
async with pool.acquire() as conn:
try:
async with conn.cursor(aiomysql.DictCursor) as cur:
await cur.execute(sql, args)
return await cur.fetchall()
finally:
conn.close()
async def insert_instagram_row(hospital_id: str, url: str) -> int:
return await execute("INSERT INTO instagram_data (hospital_id, url) VALUES (%s, %s)", (hospital_id, url))
@@ -247,3 +258,14 @@ async def save_hospital_raw_data(hospital_id: str, data: dict, analysis_run_id:
),
)
await _insert_hospital_history(hospital_id, analysis_run_id)
async def get_market_analysis(analysis_run_id: str) -> dict:
rows = await fetchall(
"SELECT analysis_type, data FROM market_analysis WHERE analysis_run_id = %s AND status = 'done'",
(analysis_run_id,),
)
return {
row["analysis_type"]: json.loads(row["data"]) if isinstance(row["data"], str) else row["data"]
for row in rows
}