#!/usr/bin/env python3
"""
Demo script to create a Cal.com appointment with a specific location
for testing our MCP-enhanced weather integration.
"""
import os
import requests
import json
from datetime import datetime, timedelta
from dotenv import load_dotenv
def create_appointment_with_location():
"""Creates a demo appointment with a location for weather testing."""
load_dotenv()
api_key = os.getenv("CALCOM_API_KEY")
if not api_key:
print("❌ CALCOM_API_KEY not found")
return
# Create appointment for tomorrow at 4 PM
tomorrow = datetime.now() + timedelta(days=1)
start_time = tomorrow.replace(hour=16, minute=0, second=0, microsecond=0)
# The booking data structure based on MCP Context7 research
booking_data = {
"start": start_time.isoformat() + "Z",
"eventTypeId": 1, # Using the first event type (30 Min Meeting)
"responses": {
"name": "MCP Demo User",
"email": "mcp-demo@example.com",
"location": {
"label": "location",
"value": "San Francisco, CA" # Specific location for weather lookup
},
"notes": "Testing MCP weather integration - created via Context7 research"
},
"timeZone": "America/New_York",
"language": "en",
"userId": 1591474, # From your original script
"status": "ACCEPTED"
}
url = f"https://api.cal.com/v1/bookings?apiKey={api_key}"
headers = {"Content-Type": "application/json"}
try:
response = requests.post(url, headers=headers, data=json.dumps(booking_data))
response.raise_for_status()
result = response.json()
print("🎉 Successfully created appointment with location!")
print(f" 📋 Title: {result.get('title', 'N/A')}")
print(f" 📍 Location: San Francisco, CA")
print(f" 🕐 Time: {start_time.strftime('%A, %B %d at %I:%M %p')}")
print(f" 🆔 UID: {result.get('uid', 'N/A')}")
return result
except requests.exceptions.RequestException as e:
print(f"❌ Error creating appointment: {e}")
if e.response is not None:
print(f"Response: {e.response.status_code}")
try:
error_detail = e.response.json()
print(f"Details: {error_detail}")
except:
print(f"Raw response: {e.response.text}")
return None
if __name__ == "__main__":
print("🌤️ Creating appointment with location for MCP weather demo...")
create_appointment_with_location()