import os, sys, json, time, uuid

with open('.env', 'r') as f:
    for line in f:
        line = line.strip()
        if not line or line.startswith('#') or '=' not in line:
            continue
        k, _, v = line.partition('=')
        os.environ.setdefault(k.strip(), v.strip().strip('"').strip("'"))

sys.path.insert(0, '.')

from videoautomation.models import init_video_tables
from videoautomation.pipeline import run_pipeline

init_video_tables()
task_id = uuid.uuid4().hex

instruction = (
    "Create a 6-scene promotional video about using BizNode for affiliate marketing. "
    "Scene 1 Hook: Open with the problem - affiliate marketers struggle to manage campaigns and track conversions manually. "
    "Scene 2 Introduction: Introduce BizNode as the AI-powered affiliate marketing command center. "
    "Scene 3 Features: Automated lead tracking via Telegram bot, AI partner onboarding, real-time commission dashboard, smart payout scheduling. "
    "Scene 4 How It Works: Affiliate signs up via Telegram, BizNode tracks referrals, calculates commissions, sends payment notifications. "
    "Scene 5 Results: 3x faster partner onboarding, 90 percent reduction in manual tracking, automated daily reports. "
    "Scene 6 CTA: Visit biznode.1bz.biz to start automating your affiliate program today."
)

print("Task ID:", task_id[:8])
print("Starting full pipeline...")
start = time.time()
result = run_pipeline(task_id, instruction, source="dashboard", source_user="owner")
elapsed = time.time() - start

print("Time: %.1fs" % elapsed)
print("Status:", result.get("status"))
if result.get("output_path"):
    size = os.path.getsize(result["output_path"]) / 1024 / 1024
    print("Output: %s (%.1f MB)" % (result["output_path"], size))
if result.get("error"):
    print("Error:", result["error"])
