#!/usr/bin/env python3 """ Show all platform, admin, vendor, and storefront URLs. Queries the database for platforms, vendors, 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_vendors(db): """Get all vendors with company info.""" return db.execute( text( "SELECT v.id, v.vendor_code, v.name, v.subdomain, v.is_active, " " c.name AS company_name " "FROM vendors v " "LEFT JOIN companies c ON c.id = v.company_id " "ORDER BY c.name, v.name" ) ).fetchall() def get_vendor_domains(db): """Get all custom vendor domains.""" return db.execute( text( "SELECT vd.vendor_id, vd.domain, vd.is_primary, vd.is_active, " " vd.is_verified, v.vendor_code " "FROM vendor_domains vd " "JOIN vendors v ON v.id = vd.vendor_id " "ORDER BY vd.vendor_id, vd.is_primary DESC" ) ).fetchall() def status_badge(is_active): return "active" if is_active else "INACTIVE" def print_dev_urls(platforms, vendors, vendor_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}/") # Vendors print() print(" VENDOR DASHBOARDS") domains_by_vendor = {} for vd in vendor_domains: domains_by_vendor.setdefault(vd.vendor_id, []).append(vd) current_company = None for v in vendors: if v.company_name != current_company: current_company = v.company_name print(f" [{current_company or 'No Company'}]") tag = f" [{status_badge(v.is_active)}]" if not v.is_active else "" code = v.vendor_code print(f" {v.name} ({code}){tag}") print(f" Dashboard: {DEV_BASE}/vendor/{code}/") print(f" API: {DEV_BASE}/api/v1/vendor/{code}/") # Storefronts print() print(" STOREFRONTS") current_company = None for v in vendors: if v.company_name != current_company: current_company = v.company_name print(f" [{current_company or 'No Company'}]") tag = f" [{status_badge(v.is_active)}]" if not v.is_active else "" code = v.vendor_code print(f" {v.name} ({code}){tag}") print(f" Shop: {DEV_BASE}/vendors/{code}/storefront/") print(f" API: {DEV_BASE}/api/v1/storefront/{code}/") def print_prod_urls(platforms, vendors, vendor_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 vendor domains_by_vendor = {} for vd in vendor_domains: domains_by_vendor.setdefault(vd.vendor_id, []).append(vd) # Vendors print() print(" VENDOR DASHBOARDS") current_company = None for v in vendors: if v.company_name != current_company: current_company = v.company_name print(f" [{current_company or 'No Company'}]") tag = f" [{status_badge(v.is_active)}]" if not v.is_active else "" print(f" {v.name} ({v.vendor_code}){tag}") print(f" Dashboard: https://{v.subdomain}.{platform_domain}/vendor/{v.vendor_code}/") # Storefronts print() print(" STOREFRONTS") current_company = None for v in vendors: if v.company_name != current_company: current_company = v.company_name print(f" [{current_company or 'No Company'}]") tag = f" [{status_badge(v.is_active)}]" if not v.is_active else "" print(f" {v.name} ({v.vendor_code}){tag}") # Subdomain URL print(f" Subdomain: https://{v.subdomain}.{platform_domain}/") # Custom domains vd_list = domains_by_vendor.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) vendors = get_vendors(db) vendor_domains = get_vendor_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(vendors)} vendor(s), {len(vendor_domains)} custom domain(s)") print("=" * 72) if show_dev: print_dev_urls(platforms, vendors, vendor_domains) if show_prod: print_prod_urls(platforms, vendors, vendor_domains) print() if __name__ == "__main__": main()