Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
capture_screenshots.py · 6.6 KB · 197 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """Capture screenshots of all DBBasic interfaces for documentation""" |
| 3 | |
| 4 | import os |
| 5 | import time |
| 6 | import asyncio |
| 7 | from selenium import webdriver |
| 8 | from selenium.webdriver.chrome.options import Options |
| 9 | from selenium.webdriver.common.by import By |
| 10 | from selenium.webdriver.support.ui import WebDriverWait |
| 11 | from selenium.webdriver.support import expected_conditions as EC |
| 12 | from pathlib import Path |
| 13 | |
| 14 | # Create screenshots directory |
| 15 | SCREENSHOT_DIR = Path("screenshots") |
| 16 | SCREENSHOT_DIR.mkdir(exist_ok=True) |
| 17 | |
| 18 | def setup_driver(headless=False): |
| 19 | """Setup Chrome driver with options""" |
| 20 | options = Options() |
| 21 | if headless: |
| 22 | options.add_argument('--headless') |
| 23 | options.add_argument('--no-sandbox') |
| 24 | options.add_argument('--disable-dev-shm-usage') |
| 25 | options.add_argument('--window-size=1920,1080') |
| 26 | return webdriver.Chrome(options=options) |
| 27 | |
| 28 | def capture_interface(driver, url, name, wait_selector=None, wait_time=3): |
| 29 | """Capture a screenshot of an interface""" |
| 30 | print(f"📸 Capturing {name}...") |
| 31 | driver.get(url) |
| 32 | |
| 33 | # Wait for page to load |
| 34 | if wait_selector: |
| 35 | try: |
| 36 | WebDriverWait(driver, 10).until( |
| 37 | EC.presence_of_element_located((By.CSS_SELECTOR, wait_selector)) |
| 38 | ) |
| 39 | except: |
| 40 | print(f" ⚠️ Selector {wait_selector} not found, continuing...") |
| 41 | |
| 42 | time.sleep(wait_time) # Additional wait for dynamic content |
| 43 | |
| 44 | # Capture screenshot |
| 45 | screenshot_path = SCREENSHOT_DIR / f"{name}.png" |
| 46 | driver.save_screenshot(str(screenshot_path)) |
| 47 | print(f" ✅ Saved to {screenshot_path}") |
| 48 | return screenshot_path |
| 49 | |
| 50 | def main(): |
| 51 | """Capture all interfaces""" |
| 52 | print("🚀 Starting screenshot capture for DBBasic interfaces") |
| 53 | print("=" * 60) |
| 54 | |
| 55 | driver = setup_driver(headless=False) # Set to True for headless mode |
| 56 | |
| 57 | try: |
| 58 | # Dictionary of interfaces to capture |
| 59 | # Format: (URL, filename, status, wait_selector, wait_time) |
| 60 | interfaces = [ |
| 61 | # IMPLEMENTED INTERFACES |
| 62 | ("http://localhost:8000/static/mockups.html", |
| 63 | "main_dashboard", "prototype", "#dashboard", 2), |
| 64 | |
| 65 | ("http://localhost:8003", |
| 66 | "ai_service_builder", "implemented", "h1", 2), |
| 67 | |
| 68 | ("http://localhost:8004", |
| 69 | "realtime_monitor", "implemented", "#activity-log", 3), |
| 70 | |
| 71 | ("http://localhost:8005", |
| 72 | "crud_engine_list", "implemented", "table", 2), |
| 73 | |
| 74 | ("http://localhost:8005/customers/create", |
| 75 | "crud_engine_form", "implemented", "form", 2), |
| 76 | |
| 77 | ("http://localhost:8006", |
| 78 | "test_runner", "implemented", "#test-list", 2), |
| 79 | |
| 80 | # PROTOTYPE INTERFACES (from mockups) |
| 81 | # Main mockups page (dashboard overview) |
| 82 | ("http://localhost:8000/static/mockups.html", |
| 83 | "main_dashboard", "prototype", ".container", 2), |
| 84 | |
| 85 | # Available prototype pages |
| 86 | ("http://localhost:8000/static/mockup_dashboard.html", |
| 87 | "prototype_dashboard", "prototype", "body", 2), |
| 88 | |
| 89 | ("http://localhost:8000/static/mockup_config.html", |
| 90 | "prototype_config_editor", "prototype", "body", 2), |
| 91 | |
| 92 | ("http://localhost:8000/static/mockup_ai_services.html", |
| 93 | "prototype_ai_services", "prototype", "body", 2), |
| 94 | ] |
| 95 | |
| 96 | # Capture each interface |
| 97 | screenshots = {} |
| 98 | for url, name, status, selector, wait in interfaces: |
| 99 | try: |
| 100 | path = capture_interface(driver, url, name, selector, wait) |
| 101 | screenshots[name] = { |
| 102 | 'path': path, |
| 103 | 'status': status, |
| 104 | 'url': url |
| 105 | } |
| 106 | except Exception as e: |
| 107 | print(f" ❌ Error capturing {name}: {e}") |
| 108 | |
| 109 | print("\n" + "=" * 60) |
| 110 | print("📊 Screenshot Summary:") |
| 111 | print("=" * 60) |
| 112 | |
| 113 | implemented = [k for k, v in screenshots.items() if v['status'] == 'implemented'] |
| 114 | prototypes = [k for k, v in screenshots.items() if v['status'] == 'prototype'] |
| 115 | |
| 116 | print(f"✅ Implemented interfaces captured: {len(implemented)}") |
| 117 | for name in implemented: |
| 118 | print(f" - {name}") |
| 119 | |
| 120 | print(f"\n🎨 Prototype interfaces captured: {len(prototypes)}") |
| 121 | for name in prototypes: |
| 122 | print(f" - {name}") |
| 123 | |
| 124 | # Generate markdown for README |
| 125 | print("\n" + "=" * 60) |
| 126 | print("📝 Markdown for README.md:") |
| 127 | print("=" * 60) |
| 128 | |
| 129 | markdown = """ |
| 130 | ## 📸 Interface Screenshots |
| 131 | |
| 132 | ### ✅ Implemented Interfaces |
| 133 | |
| 134 | """ |
| 135 | |
| 136 | for name, info in screenshots.items(): |
| 137 | if info['status'] == 'implemented': |
| 138 | title = name.replace('_', ' ').title() |
| 139 | markdown += f"#### {title}\n" |
| 140 | markdown += f"\n" |
| 141 | markdown += f"*Live at: {info['url']}*\n\n" |
| 142 | |
| 143 | markdown += """ |
| 144 | ### 🎨 Prototype Interfaces (Coming Soon) |
| 145 | |
| 146 | These interfaces are currently available as interactive prototypes at `http://localhost:8000/static/mockups.html` |
| 147 | |
| 148 | """ |
| 149 | |
| 150 | for name, info in screenshots.items(): |
| 151 | if info['status'] == 'prototype': |
| 152 | title = name.replace('prototype_', '').replace('_', ' ').title() |
| 153 | markdown += f"#### {title}\n" |
| 154 | markdown += f"\n" |
| 155 | markdown += f"*Prototype preview - implementation pending*\n\n" |
| 156 | |
| 157 | # Save markdown to file |
| 158 | with open(SCREENSHOT_DIR / "README_SCREENSHOTS.md", "w") as f: |
| 159 | f.write(markdown) |
| 160 | |
| 161 | print(markdown) |
| 162 | print("\n✅ Markdown saved to screenshots/README_SCREENSHOTS.md") |
| 163 | |
| 164 | finally: |
| 165 | driver.quit() |
| 166 | print("\n🎉 Screenshot capture complete!") |
| 167 | |
| 168 | if __name__ == "__main__": |
| 169 | # Check if services are running |
| 170 | import requests |
| 171 | |
| 172 | services = [ |
| 173 | ("http://localhost:8000", "Main Dashboard"), |
| 174 | ("http://localhost:8003", "AI Service Builder"), |
| 175 | ("http://localhost:8004", "Realtime Monitor"), |
| 176 | ("http://localhost:8005", "CRUD Engine"), |
| 177 | ("http://localhost:8006", "Test Runner"), |
| 178 | ] |
| 179 | |
| 180 | print("🔍 Checking services...") |
| 181 | all_running = True |
| 182 | for url, name in services: |
| 183 | try: |
| 184 | requests.get(url, timeout=1) |
| 185 | print(f" ✅ {name} is running") |
| 186 | except: |
| 187 | print(f" ❌ {name} is not running at {url}") |
| 188 | all_running = False |
| 189 | |
| 190 | if not all_running: |
| 191 | print("\n⚠️ Warning: Not all services are running. Screenshots may be incomplete.") |
| 192 | response = input("Continue anyway? (y/n): ") |
| 193 | if response.lower() != 'y': |
| 194 | exit(1) |
| 195 | |
| 196 | print() |
| 197 | main() |