import requests
from datetime import datetime

SUPABASE_URL = "https://mrngdyllepreqkxxmvqn.supabase.co/rest/v1/dispensary_content"
SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1ybmdkeWxsZXByZXFreHhtdnFuIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc1NDA5NzIxMCwiZXhwIjoyMDY5NjczMjEwfQ.lStqSjOmpDgP2gY2RGvV9MVS6HXs8e0I4wpwS0yzVDk"

title = "When Will Cannabis Be Rescheduled to Schedule III? What Florida Patients Need to Know"
slug = "schedule-iii-cannabis-rescheduling-florida-patients"
image_url = "https://cannadealsfl.com/api/images/images/blog/headers/schedule-iii-cannabis-rescheduling-florida-patients.png"

with open('/tmp/blog_content.txt', 'r') as f:
    content = f.read()

# Extract excerpt (first paragraph after intro)
excerpt = "Federal cannabis rescheduling to Schedule III could happen by fall 2026. Learn what this means for Florida's 800,000+ medical marijuana patients - from banking access to tax relief and beyond."

now = datetime.utcnow().isoformat() + "Z"

data = {
    "title": title,
    "slug": slug,
    "content": content,
    "excerpt": excerpt,
    "content_type": "news",
    "dispensary_id": "c7eba752-3ee8-4394-834e-1bf03eaf9bd5",
    "is_published": True,
    "publish_date": now,
    "meta_title": f"{title} | CannaDealsFL",
    "meta_description": excerpt,
    "featured_image_url": image_url
}

response = requests.post(
    SUPABASE_URL,
    headers={
        "apikey": SUPABASE_KEY,
        "Authorization": f"Bearer {SUPABASE_KEY}",
        "Content-Type": "application/json",
        "Prefer": "return=minimal"
    },
    json=data
)

if response.status_code in [200, 201]:
    print(f"✅ Blog post published successfully!")
    print(f"URL: https://cannadealsfl.com/blog/{slug}")
else:
    print(f"❌ Error: {response.status_code}")
    print(response.text)
