- import_products_from_mssql.py: MSSQL에서 오늘 판매된 제품 가져오기 - 바코드 + 제품명 자동 수집 (30개) - 제품명 기반 카테고리 자동 추론 - view_products.py: product_master 조회 스크립트 - 총 31개 제품 등록 완료 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
"""
|
|
product_master 제품 조회
|
|
"""
|
|
|
|
import sqlite3
|
|
import os
|
|
import json
|
|
|
|
def view_products():
|
|
"""product_master 제품 조회"""
|
|
db_path = os.path.join(os.path.dirname(__file__), 'db', 'mileage.db')
|
|
conn = sqlite3.connect(db_path)
|
|
cursor = conn.cursor()
|
|
|
|
try:
|
|
# 전체 제품 수
|
|
cursor.execute("SELECT COUNT(*) FROM product_master")
|
|
total = cursor.fetchone()[0]
|
|
print(f"전체 제품 수: {total}개\n")
|
|
|
|
# 카테고리별 제품 수
|
|
print("="*80)
|
|
print("카테고리별 제품 수")
|
|
print("="*80)
|
|
cursor.execute("""
|
|
SELECT
|
|
category_name,
|
|
COUNT(*) as count
|
|
FROM product_category_mapping
|
|
GROUP BY category_name
|
|
ORDER BY count DESC
|
|
""")
|
|
for cat, count in cursor.fetchall():
|
|
print(f"{cat:20} : {count:3}개")
|
|
|
|
# 제품 목록 (카테고리 포함)
|
|
print("\n" + "="*80)
|
|
print("제품 목록 (카테고리 포함)")
|
|
print("="*80)
|
|
cursor.execute("""
|
|
SELECT
|
|
p.barcode,
|
|
p.product_name,
|
|
GROUP_CONCAT(m.category_name, ', ') as categories,
|
|
p.is_verified
|
|
FROM product_master p
|
|
LEFT JOIN product_category_mapping m ON p.barcode = m.barcode
|
|
GROUP BY p.barcode
|
|
ORDER BY p.product_name
|
|
""")
|
|
|
|
for row in cursor.fetchall():
|
|
barcode, name, cats, verified = row
|
|
verified_mark = "[V]" if verified else "[ ]"
|
|
cats_str = cats if cats else "(카테고리 없음)"
|
|
print(f"{verified_mark} {name:30} -> {cats_str}")
|
|
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
view_products()
|