Files
test-mcp/diag_folders.py

67 lines
2.5 KiB
Python

import asyncio, os, json, re, sys
from playwright.async_api import async_playwright
from dotenv import load_dotenv
load_dotenv()
async def run_diagnostics():
user_id = os.getenv("PM_USER_ID")
password = os.getenv("PM_PASSWORD")
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
context = await browser.new_context(viewport={"width": 1600, "height": 900})
page = await context.new_page()
print(">>> 로그인 중...")
await page.goto("https://overseas.projectmastercloud.com/dashboard")
if await page.locator("#login-by-id").is_visible(timeout=5000):
await page.click("#login-by-id")
await page.fill("#user_id", user_id)
await page.fill("#user_pw", password)
await page.click("#login-btn")
await page.wait_for_selector("h4.list__contents_aria_group_body_list_item_label", timeout=60000)
project_name = "필리핀 사무소"
print(f">>> [{project_name}] 폴더 전수 조사 시작...")
target_el = page.get_by_text(project_name).first
await target_el.scroll_into_view_if_needed()
await target_el.click(force=True)
await asyncio.sleep(10) # 충분한 로딩 대기
print("\n" + "="*60)
print(f"{'No':<4} | {'Folder Name':<40} | {'Files'}")
print("-" * 60)
# fetch 결과를 직접 리턴받음
tree_data = await page.evaluate("""async () => {
const resp = await fetch('/api/getTreeObject?params[storageType]=CLOUD&params[resourcePath]=/');
return await resp.json();
}""")
if tree_data:
tree = tree_data.get('currentTreeObject', {})
folders = tree.get('folder', {})
folder_items = list(folders.values()) if isinstance(folders, dict) else (folders if isinstance(folders, list) else [])
total_sum = 0
for i, f in enumerate(folder_items):
name = f.get('name', 'Unknown')
count = int(f.get('filesCount', 0))
total_sum += count
print(f"{i+1:<4} | {name:<40} | {count}")
print("-" * 60)
print(f">>> 총 {len(folder_items)}개 폴더 발견 | 전체 파일 합계: {total_sum}")
print("="*60)
else:
print(">>> [오류] 데이터를 가져오지 못했습니다.")
await browser.close()
if __name__ == "__main__":
asyncio.run(run_diagnostics())