#!/usr/bin/env python3 """ Show all platform, admin, store, and storefront URLs. Queries the database for platforms, stores, and custom domains, then prints all accessible URLs for both development and production. Usage: python scripts/show_urls.py # Show all URLs python scripts/show_urls.py --dev # Development URLs only python scripts/show_urls.py --prod # Production URLs only """ import argparse import sys from sqlalchemy import text from app.core.config import settings from app.core.database import SessionLocal DEV_BASE = "http://localhost:9999" SEPARATOR = "─" * 72 def get_platforms(db): """Get all platforms.""" return db.execute( text( "SELECT id, code, name, domain, path_prefix, is_active " "FROM platforms ORDER BY code" ) ).fetchall() def get_stores(db): """Get all stores with merchant info.""" return db.execute( text( "SELECT v.id, v.store_code, v.name, v.subdomain, v.is_active, " " c.name AS merchant_name " "FROM stores v " "LEFT JOIN merchants c ON c.id = v.merchant_id " "ORDER BY c.name, v.name" ) ).fetchall() def get_store_domains(db): """Get all custom store domains.""" return db.execute( text( "SELECT vd.store_id, vd.domain, vd.is_primary, vd.is_active, " " vd.is_verified, v.store_code " "FROM store_domains vd " "JOIN stores v ON v.id = vd.store_id " "ORDER BY vd.store_id, vd.is_primary DESC" ) ).fetchall() def status_badge(is_active): return "active" if is_active else "INACTIVE" def print_dev_urls(platforms, stores, store_domains): """Print all development URLs.""" print() print("DEVELOPMENT URLS") print(f"Base: {DEV_BASE}") print(SEPARATOR) # Admin print() print(" ADMIN PANEL") print(f" Login: {DEV_BASE}/admin/login") print(f" Dashboard: {DEV_BASE}/admin/") print(f" API: {DEV_BASE}/api/v1/admin/") print(f" API Docs: {DEV_BASE}/docs") # Platforms print() print(" PLATFORMS") for p in platforms: tag = f" [{status_badge(p.is_active)}]" if not p.is_active else "" prefix = p.path_prefix or "" if p.code == "main": print(f" {p.name}{tag}") print(f" Home: {DEV_BASE}/") else: print(f" {p.name} ({p.code}){tag}") if prefix: print(f" Home: {DEV_BASE}/platforms/{p.code}/") else: print(f" Home: {DEV_BASE}/platforms/{p.code}/") # Stores print() print(" STORE DASHBOARDS") domains_by_store = {} for vd in store_domains: domains_by_store.setdefault(vd.store_id, []).append(vd) current_merchant = None for v in stores: if v.merchant_name != current_merchant: current_merchant = v.merchant_name print(f" [{current_merchant or 'No Merchant'}]") tag = f" [{status_badge(v.is_active)}]" if not v.is_active else "" code = v.store_code print(f" {v.name} ({code}){tag}") print(f" Dashboard: {DEV_BASE}/store/{code}/") print(f" API: {DEV_BASE}/api/v1/store/{code}/") # Storefronts print() print(" STOREFRONTS") current_merchant = None for v in stores: if v.merchant_name != current_merchant: current_merchant = v.merchant_name print(f" [{current_merchant or 'No Merchant'}]") tag = f" [{status_badge(v.is_active)}]" if not v.is_active else "" code = v.store_code print(f" {v.name} ({code}){tag}") print(f" Shop: {DEV_BASE}/stores/{code}/storefront/") print(f" API: {DEV_BASE}/api/v1/storefront/{code}/") def print_prod_urls(platforms, stores, store_domains): """Print all production URLs.""" platform_domain = settings.platform_domain print() print("PRODUCTION URLS") print(f"Platform domain: {platform_domain}") print(SEPARATOR) # Admin print() print(" ADMIN PANEL") print(f" Login: https://admin.{platform_domain}/admin/login") print(f" Dashboard: https://admin.{platform_domain}/admin/") print(f" API: https://admin.{platform_domain}/api/v1/admin/") # Platforms print() print(" PLATFORMS") for p in platforms: tag = f" [{status_badge(p.is_active)}]" if not p.is_active else "" if p.domain: print(f" {p.name} ({p.code}){tag}") print(f" Home: https://{p.domain}/") elif p.code == "main": print(f" {p.name}{tag}") print(f" Home: https://{platform_domain}/") else: print(f" {p.name} ({p.code}){tag}") print(f" Home: https://{p.code}.{platform_domain}/") # Group domains by store domains_by_store = {} for vd in store_domains: domains_by_store.setdefault(vd.store_id, []).append(vd) # Stores print() print(" STORE DASHBOARDS") current_merchant = None for v in stores: if v.merchant_name != current_merchant: current_merchant = v.merchant_name print(f" [{current_merchant or 'No Merchant'}]") tag = f" [{status_badge(v.is_active)}]" if not v.is_active else "" print(f" {v.name} ({v.store_code}){tag}") print(f" Dashboard: https://{v.subdomain}.{platform_domain}/store/{v.store_code}/") # Storefronts print() print(" STOREFRONTS") current_merchant = None for v in stores: if v.merchant_name != current_merchant: current_merchant = v.merchant_name print(f" [{current_merchant or 'No Merchant'}]") tag = f" [{status_badge(v.is_active)}]" if not v.is_active else "" print(f" {v.name} ({v.store_code}){tag}") # Subdomain URL print(f" Subdomain: https://{v.subdomain}.{platform_domain}/") # Custom domains vd_list = domains_by_store.get(v.id, []) for vd in vd_list: d_flags = [] if vd.is_primary: d_flags.append("primary") if not vd.is_active: d_flags.append("INACTIVE") if not vd.is_verified: d_flags.append("unverified") suffix = f" ({', '.join(d_flags)})" if d_flags else "" print(f" Custom: https://{vd.domain}/{suffix}") def main(): parser = argparse.ArgumentParser(description="Show all platform URLs") parser.add_argument("--dev", action="store_true", help="Development URLs only") parser.add_argument("--prod", action="store_true", help="Production URLs only") args = parser.parse_args() show_dev = args.dev or (not args.dev and not args.prod) show_prod = args.prod or (not args.dev and not args.prod) db = SessionLocal() try: platforms = get_platforms(db) stores = get_stores(db) store_domains = get_store_domains(db) except Exception as e: print(f"Error querying database: {e}", file=sys.stderr) sys.exit(1) finally: db.close() print() print("=" * 72) print(" WIZAMART PLATFORM - ALL URLS") print(f" {len(platforms)} platform(s), {len(stores)} store(s), {len(store_domains)} custom domain(s)") print("=" * 72) if show_dev: print_dev_urls(platforms, stores, store_domains) if show_prod: print_prod_urls(platforms, stores, store_domains) print() if __name__ == "__main__": main()