Add refactoring.md

This commit is contained in:
2026-05-02 16:36:13 +09:00
parent 859c39fe0c
commit 3c6df12e70
3 changed files with 1688 additions and 32 deletions

76
cli.py
View File

@@ -15,6 +15,8 @@ from playwright.sync_api import sync_playwright
from commands.base import add_common_arguments, load_report
from commands.record import run as run_record
DEFAULT_BASE_URL = "http://58.229.253.168:8089"
def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Baseball Automation CLI")
@@ -39,40 +41,42 @@ def _parse_args() -> argparse.Namespace:
def interactive_mode() -> int:
print("=== Baseball Automation CLI ===")
print("1. 네이버 데이터 크롤링 (crawl)")
print("2. 관리자 사이트 기록 자동 입력 (record)")
print("3. 크롤링 + 기록 입력 한 번에 실행 (crawl & record)")
print("2. 관리자 사이트 라인업 입력 (lineup)")
print("3. 관리자 사이트 기록 자동 입력 (record)")
print("4. 크롤링 + 라인업 + 기록 한 번에 실행 (crawl -> lineup -> record)")
choice = input("\n실행할 작업을 선택하세요 (1/2/3) [3]: ").strip() or "3"
if choice not in {"1", "2", "3"}:
print("잘못된 선택입니다.")
choice = input("\n실행할 작업을 선택하세요 (1/2/3/4) [4]: ").strip() or "4"
if choice not in {"1", "2", "3", "4"}:
print("잘못된 입력입니다.")
return 1
game_id = input("경기 ID를 입력하세요 (예: 20260501NCLG02026): ").strip()
if not game_id:
print("경기 ID가 필요합니다.")
return 1
game_id = "".join(game_id.split())
base_url = ""
user_data_dir = ""
if choice in {"2", "3"}:
base_url = input("기록 사이트 기본 URL을 입력하세요 (엔터 시 site.txt 자동 참조): ").strip()
if not base_url:
site_txt = Path("site.txt")
if site_txt.exists():
lines = site_txt.read_text(encoding="utf-8").splitlines()
if lines and lines[0].startswith("http"):
from urllib.parse import urlparse
parsed = urlparse(lines[0])
base_url = f"{parsed.scheme}://{parsed.netloc}"
print(f"👉 [자동 설정] 기록 사이트 URL: {base_url}")
if not base_url:
base_url = input("URL을 찾을 수 없습니다. 직접 입력하세요: ").strip()
if not base_url:
print("URL이 필요합니다.")
return 1
base_url = DEFAULT_BASE_URL
user_data_dir = None
manager_game_no = ""
if choice in {"2", "3", "4"}:
base_url_input = input("기록 사이트 기본 URL을 입력하세요 (엔터 시 site.txt 자동 참조): ").strip()
if base_url_input:
base_url = base_url_input
else:
try:
site_txt_path = Path("site.txt")
if site_txt_path.exists():
lines = site_txt_path.read_text(encoding="utf-8").splitlines()
if lines and lines[0].startswith("http"):
from urllib.parse import urlparse
parsed = urlparse(lines[0])
base_url = f"{parsed.scheme}://{parsed.netloc}"
print(f"👉 [자동 설정] 기록 사이트 URL: {base_url}")
except Exception as e:
print(f"site.txt 파일을 읽는 중 오류가 발생했습니다: {e}")
return 1
user_data_dir = input("크롬 프로필 경로를 입력하세요 (엔터 시 임시 세션): ").strip()
manager_game_no = input("관리자 사이트 게임번호를 입력하세요 (예: 11211, 모르면 엔터): ").strip()
@@ -92,9 +96,10 @@ def interactive_mode() -> int:
start_inning=None,
end_inning=None,
output_dir="output",
save=True, # for lineup
)
if choice in {"1", "3"}:
if choice in {"1", "4"}:
from crawler.report_builder import build_report, filter_report, save_report
print(f"\n[{args.game_id}] 데이터 크롤링 시작...")
report = build_report(args.game_id)
@@ -102,12 +107,19 @@ def interactive_mode() -> int:
out_path = save_report(filtered, Path(args.output_dir))
print(f"✅ 크롤링 및 리포트 저장 완료: {out_path}")
if choice in {"2", "3"}:
if choice in {"2", "3", "4"}:
report_path = Path(args.output_dir) / f"{args.game_id}_report.json"
report = load_report(report_path)
print(f"\n[{args.game_id}] 관리자 사이트 자동 입력 시작...")
with sync_playwright() as playwright:
run_record(playwright, args, report)
if choice in {"2", "4"}:
from commands.lineup import run as run_lineup
run_lineup(playwright, args, report)
if choice in {"3", "4"}:
from commands.record import run as run_record
print(f"\n[{args.game_id}] 관리자 사이트 기록 자동 입력 시작...")
run_record(playwright, args, report)
return 0