import requests
import time

KLAVIYO_API_KEY = "pk_ed88b4c0802df1432eb2289b6de3119e11"
API_URL = "https://a.klaviyo.com/api/metric/track"
SENDER_ID = "+18449223813"

customers = [
    {
        "phone": "+12104138476",
        "name": "Sarah",
        "favorite_meal": "BBQ Chicken Bowl",
        "code": "BBQ20"
    },
    # ...more
]

for i, c in enumerate(customers, start=1):
    payload = {
        "token": KLAVIYO_API_KEY,
        "event": "SMS Sent",
        "customer_properties": {
            "$phone_number": c["phone"],
            "$first_name": c["name"]
        },
        "properties": {
            "body": (
                f"Hi {c['name']}! Your favorite “{c['favorite_meal']}” "
                f"is 20% off this week. Use code {c['code']}!"
            ),
            "sender": SENDER_ID
        }
    }

    res = requests.post(API_URL, json=payload)
    print(f"[{res.status_code}] Sent to {c['phone']}: {res.text}")

    if i % 15 == 0:
        time.sleep(1)