|
""" |
|
システムスクリーンショット自動取得ツール |
|
===================================== |
|
|
|
RPA機能を使用してシステムの画面キャプチャを自動取得 |
|
""" |
|
|
|
import os |
|
import time |
|
from pathlib import Path |
|
import subprocess |
|
from controllers.conversation_logger import log_this_conversation |
|
|
|
def capture_system_screenshots(): |
|
"""システムのスクリーンショットを自動取得""" |
|
|
|
screenshots_dir = Path("/workspaces/fastapi_django_main_live/docs/images/screenshots") |
|
screenshots_dir.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
capture_targets = [ |
|
{ |
|
"url": "https://ideal-halibut-4q5qp79g2jp9-7860.app.github.dev/", |
|
"filename": "main_dashboard.png", |
|
"description": "メインダッシュボード" |
|
}, |
|
{ |
|
"url": "http://localhost:7865", |
|
"filename": "contbk_dashboard.png", |
|
"description": "ContBK統合ダッシュボード" |
|
} |
|
] |
|
|
|
results = [] |
|
|
|
for target in capture_targets: |
|
try: |
|
print(f"📸 スクリーンショット取得中: {target['description']}") |
|
|
|
|
|
result = capture_webpage_screenshot( |
|
url=target["url"], |
|
output_path=screenshots_dir / target["filename"], |
|
description=target["description"] |
|
) |
|
|
|
results.append({ |
|
"target": target, |
|
"success": result, |
|
"file_path": screenshots_dir / target["filename"] |
|
}) |
|
|
|
print(f"{'✅' if result else '❌'} {target['description']}: {result}") |
|
|
|
except Exception as e: |
|
print(f"❌ エラー: {target['description']} - {e}") |
|
results.append({ |
|
"target": target, |
|
"success": False, |
|
"error": str(e) |
|
}) |
|
|
|
return results |
|
|
|
def capture_webpage_screenshot(url: str, output_path: Path, description: str) -> bool: |
|
"""Webページのスクリーンショットを取得""" |
|
|
|
try: |
|
|
|
from contbk.gra_12_rpa.rpa_automation import take_screenshot_of_url |
|
|
|
|
|
success = take_screenshot_of_url( |
|
url=url, |
|
output_file=str(output_path), |
|
wait_time=3 |
|
) |
|
|
|
if success and output_path.exists(): |
|
print(f"✅ スクリーンショット保存: {output_path}") |
|
return True |
|
else: |
|
print(f"❌ スクリーンショット取得失敗: {url}") |
|
return False |
|
|
|
except ImportError: |
|
print("⚠️ RPA機能が利用できません。別の方法を試します...") |
|
return capture_with_selenium(url, output_path) |
|
except Exception as e: |
|
print(f"❌ RPA機能エラー: {e}") |
|
return capture_with_selenium(url, output_path) |
|
|
|
def capture_with_selenium(url: str, output_path: Path) -> bool: |
|
"""Seleniumを使用してスクリーンショット取得""" |
|
|
|
try: |
|
from selenium import webdriver |
|
from selenium.webdriver.chrome.options import Options |
|
|
|
|
|
chrome_options = Options() |
|
chrome_options.add_argument("--headless") |
|
chrome_options.add_argument("--no-sandbox") |
|
chrome_options.add_argument("--disable-dev-shm-usage") |
|
chrome_options.add_argument("--window-size=1920,1080") |
|
|
|
|
|
driver = webdriver.Chrome(options=chrome_options) |
|
|
|
try: |
|
|
|
driver.get(url) |
|
time.sleep(3) |
|
|
|
|
|
driver.save_screenshot(str(output_path)) |
|
|
|
print(f"✅ Seleniumでスクリーンショット取得: {output_path}") |
|
return True |
|
|
|
finally: |
|
driver.quit() |
|
|
|
except ImportError: |
|
print("⚠️ Seleniumが利用できません") |
|
return False |
|
except Exception as e: |
|
print(f"❌ Seleniumエラー: {e}") |
|
return False |
|
|
|
def upload_screenshots_to_git(): |
|
"""スクリーンショットをGitにコミット""" |
|
|
|
try: |
|
|
|
result = subprocess.run([ |
|
'git', 'add', 'docs/images/screenshots/' |
|
], capture_output=True, text=True, cwd='/workspaces/fastapi_django_main_live') |
|
|
|
if result.returncode == 0: |
|
print("✅ スクリーンショットをGitにステージング") |
|
else: |
|
print(f"⚠️ Git add警告: {result.stderr}") |
|
|
|
|
|
result = subprocess.run([ |
|
'git', 'commit', '-m', |
|
'📸 システムスクリーンショット追加\n\n- メインダッシュボードキャプチャ\n- ContBK統合ダッシュボードキャプチャ\n- ドキュメント用画面資料完備' |
|
], capture_output=True, text=True, cwd='/workspaces/fastapi_django_main_live') |
|
|
|
if result.returncode == 0: |
|
print("✅ スクリーンショットをコミット") |
|
return True |
|
else: |
|
print(f"⚠️ コミット結果: {result.stderr}") |
|
return False |
|
|
|
except Exception as e: |
|
print(f"❌ Git操作エラー: {e}") |
|
return False |
|
|
|
def main(): |
|
"""メイン実行関数""" |
|
|
|
print("🚀 システムスクリーンショット自動取得開始...") |
|
|
|
|
|
results = capture_system_screenshots() |
|
|
|
|
|
successful_captures = [r for r in results if r.get('success', False)] |
|
|
|
print(f"\n📊 取得結果: {len(successful_captures)}/{len(results)} 成功") |
|
|
|
if successful_captures: |
|
print("\n✅ 取得成功:") |
|
for result in successful_captures: |
|
print(f" - {result['target']['description']}: {result['file_path']}") |
|
|
|
|
|
if upload_screenshots_to_git(): |
|
print("\n🎉 スクリーンショットのアップロード完了!") |
|
else: |
|
print("\n⚠️ Gitアップロードでエラーが発生しました") |
|
else: |
|
print("\n❌ スクリーンショット取得に失敗しました") |
|
|
|
|
|
log_this_conversation( |
|
user_msg="キャプチャした資料はアップした?", |
|
assistant_msg=f"スクリーンショット自動取得ツールを作成・実行しました。{len(successful_captures)}/{len(results)}個のスクリーンショット取得に成功。", |
|
context="システムスクリーンショット自動取得", |
|
files=["screenshot_capture.py", "docs/images/screenshots/"], |
|
tools=["RPA", "Selenium", "Git"], |
|
tags=["screenshot", "documentation", "automation"] |
|
) |
|
|
|
return results |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|